On this page
Trait Function1.Function1
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.
Supertypes | |
---|---|
Known subtypes |
219 types |
Self type |
Abstract methods
Source
def apply(v1: T1): R
Apply the body of this function to the argument.
Returns | the result of function application. |
---|
Concrete methods
Source
def andThen[A](g: R => A): T1 => A
Composes two instances of Function1 in a new Function1, with this function applied first.
Type parameters |
|
---|---|
Value parameters |
|
Returns | a new function |
Source
def compose[A](g: A => T1): A => R
Composes two instances of Function1 in a new Function1, with this function applied last.
Type parameters |
|
---|---|
Value parameters |
|
Returns | a new function |
Source
Returns a string representation of the object.
The default representation is platform dependent.
Returns | a string representation of the object. |
---|---|
Definition Classes | Any |
Source
def unlift: PartialFunction[A, B]
Converts an optional function to a partial function.
Example | Unlike Function.unlift, this UnliftOps.unlift method can be used in extractors.
|
---|
© 2002-2022 EPFL, with contributions from Lightbend.
Licensed under the Apache License, Version 2.0.
https://scala-lang.org/api/3.2.0/scala/Function1.html