Skip to content

Commit 292b84f

Browse files
committed
language tour: multiple parameter lists: more on currying
1 parent 0dcda02 commit 292b84f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

_tour/multiple-parameter-lists.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,21 @@ being derived from single-parameter functions.
116116
2) There is danger of confusion with the Scala standard library's
117117
[`curried`](https://www.scala-lang.org/api/current/scala/Function2.html#curried:T1=%3E(T2=%3ER))
118118
and [`uncurried`](https://www.scala-lang.org/api/current/scala/Function$.html#uncurried[T1,T2,R](f:T1=%3E(T2=%3ER)):(T1,T2)=%3ER) methods, which don't involve multiple parameter lists at all.
119+
120+
Regardless, there are certainly similarities to be found between
121+
multiple parameter lists and currying. Though they are different at
122+
the definition site, the call site might nonetheless look identical,
123+
as in this example:
124+
125+
```scala mdoc
126+
// version with multiple parameter lists
127+
def addMultiple(n1: Int)(n2: Int) = n1 + n2
128+
// two different ways of arriving at a curried version instead
129+
def add(n1: Int, n2: Int) = n1 + n2
130+
val addCurried1 = (add _).curried
131+
val addCurried2 = (n1: Int) => (n2: Int) => n1 + n2
132+
// regardless, all three call sites are identical
133+
addMultiple(3)(4) // 7
134+
addCurried1(3)(4) // 7
135+
addCurried2(3)(4) // 7
136+
```

0 commit comments

Comments
 (0)