This article covers what you are looking at Partially-Applied Functions (and Currying) in Scala | alvinalexander.com. In this case test2
os a partially applied function.
Usually this is just for syntactic reasons (in my experience).
Consider the following
val in = List(6,5,4,3,2,1,2,3,4,5,6)
def isFactorOf(n: number)(maybeFactor: number): boolean = ???
val isFactorOfFirst = isFactorOf(in.head)
val isFactorOfLast = isFactorOf(in.last)
in
.filter(isFactorOfFirst)
.map(x => x*x)
.filter(isFactorOfLast)
This could also be written like this
val in = List(6,5,4,3,2,1,2,3,4,5,6)
def isFactorOf(n: number)(maybeFactor: number): boolean = ???
val first = in.head
val last = in.last
in
.filter(isFactorOf(first))
.map(x => x*x)
.filter(isFactorOf(last))
Or
val in = List(6,5,4,3,2,1,2,3,4,5,6)
def isFactorOf(n: number, maybeFactor: number): boolean = ???
val first = in.head
val last = in.last
in
.filter(isFactorOf(first, _))
.map(x => x*x)
.filter(isFactorOf(last, _))
(there are probably a miriad of other ways to write this).
In scala 2 currying is also used to help the compiler with type inference IIRC.
Consider this trivial scastie, the uncurried variant doesn’t infer the types correctly at the callsite (this is fixed in scala 3). Scastie - An interactive playground for Scala.
…
It will be interesting to see what others make of currying and partially applied functions though