Partial function application


In [1]:
def f(a: Int, b: Double) = a + b


defined function f

In [4]:
// Provide b only
// g is now a function that only takes an Int (first argument)
def g = f(_: Int, 2d)


defined function g

In [6]:
// g: Int => Double
g


res5: Int => Double = <function1>

In [5]:
g(2)


res4: Double = 4.0

In [8]:
// Provide "a" only
def h = f(1, _: Double)


defined function h

In [9]:
h


res8: Double => Double = <function1>

In [10]:
h(3d)


res9: Double = 4.0

Currying


In [11]:
val f = (a: Int, b: Double, c: String) => a + b + c


f: (Int, Double, String) => String = <function3>

In [13]:
// Curry it
val fCurried = f.curried


fCurried: Int => Double => String => String = <function1>

In [14]:
fCurried(1)


res13: Double => String => String = <function1>

In [ ]:
fCurri

Acknowledgement

Thanks to @deaktator for explaining these to me