A function of 1 parameter.
A function of 1 parameter.
In the following example, the definition of succ is a shorthand for the anonymous class definition anonfun1:
object Main extends App {
val succ = (x: Int) => x + 1
val anonfun1 = new Function1[Int, Int] {
def apply(x: Int): Int = x + 1
}
assert(succ(0) == anonfun1(0))
}
Note that the difference between Function1
and scala.PartialFunction
is that the latter can specify inputs which it will not handle.
- Companion
- object
Value members
Abstract methods
Concrete methods
Composes two instances of Function1 in a new Function1, with this function applied first.
Composes two instances of Function1 in a new Function1, with this function applied first.
- Type Params
- A
the result type of function
g
- Value Params
- g
a function R => A
- Returns
a new function
f
such thatf(x) == g(apply(x))
Composes two instances of Function1 in a new Function1, with this function applied last.
Composes two instances of Function1 in a new Function1, with this function applied last.
- Type Params
- A
the type to which function
g
can be applied
- Value Params
- g
a function A => T1
- Returns
a new function
f
such thatf(x) == apply(g(x))