Skip to content

[Tour] Currying section could add more explanations to Partial application #2190

@gaopinghuang0

Description

@gaopinghuang0

The current Partial application in the multiple parameter lists section is as follows.

val numbers = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
val numberFunc = numbers.foldLeft(List[Int]()) _

val squares = numberFunc((xs, x) => xs :+ x*x)
println(squares) // List(1, 4, 9, 16, 25, 36, 49, 64, 81, 100)

val cubes = numberFunc((xs, x) => xs :+ x*x*x)
println(cubes)  // List(1, 8, 27, 64, 125, 216, 343, 512, 729, 1000)

It'd be better to remind the reader of the syntax of using _ at the end of the numberFunc definition.
Also, it would be helpful to explain the :+ operator and add a hyperlink for more details.

Missing those explanations makes it hard to understand.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions