#scala
by adding the η-expansion postfix operator (η is pronounced "eta"), we can turn the method into a function value.
If you want to change selection, open document below and click on "Move attachment"
tpolecat with `_' if you want to treat it as a partially applied function
val f = add1
^
Note also the type of add1, which doesn't look normal; you can't declare a variable of type (n: Int)Int. Methods are not values.
However, <span>by adding the η-expansion postfix operator (η is pronounced "eta"), we can turn the method into a function value. Note the type of f.
scala> val f = add1 _
f: Int => Int =
scala> f(3)
res0: Int = 4
The effect of _ is to perform the equivalent of the following: we construct a Function1 in Summary
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Details