Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

separate Scala 2/3 example for partial application in _tour/multiple-parameter-lists.md #3156

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

AlecVercruysse
Copy link

I ran the example code in a Scala 3.6.3 repl to understand the behavior of the underscore. The interpreter warns that the syntax is no longer supported:

scala> val numbers = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
val numbers: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

scala> val numberFunc = numbers.foldLeft(List[Int]())
val numberFunc: ((List[Int], Int) => List[Int]) => List[Int] = Lambda$1752/0x0000008001565820@a4dcede

scala> numberFunc((xs, x) => xs :+ x*x)
val res1: List[Int] = List(1, 4, 9, 16, 25, 36, 49, 64, 81, 100)

scala> val numberFunc = numbers.foldLeft(List[Int]()) _
1 warning found
-- Warning: ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1 |val numberFunc = numbers.foldLeft(List[Int]()) _
  |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |                 The syntax `<function> _` is no longer supported;
  |                 you can simply leave out the trailing ` _`
val numberFunc: ((List[Int], Int) => List[Int]) => List[Int] = Lambda$1786/0x00000080015b59c0@2634d000

So I propose providing separate tabs for Scala 2 vs Scala 3.

Copy link
Member

@adpi2 adpi2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants