Function | API reference | Android Developers (original) (raw)
@FunctionalInterface interface Function<T : Any!, R : Any!>
Known Direct Subclasses
| UnaryOperator | Represents an operation on a single operand that produces a result of the same type as its operand. |
|---|
Represents a function that accepts one argument and produces a result.
This is a functional interface whose functional method is [apply(java.lang.Object)](#apply%28java.util.function.Function.T%29).
Summary
| Public methods | |
|---|---|
| open Function<T, V>! | andThen(after: Function<in R, out V>!) Returns a composed function that first applies this function to its input, and then applies the after function to the result. |
| abstract R | apply(t: T) Applies this function to the given argument. |
| open Function<V, R>! | compose(before: Function<in V, out T>!) Returns a composed function that first applies the before function to its input, and then applies this function to the result. |
| open static Function<T, T>! | identity() Returns a function that always returns its input argument. |
Public methods
andThen
open fun <V : Any!> andThen(after: Function<in R, out V>!): Function<T, V>!
Returns a composed function that first applies this function to its input, and then applies the after function to the result. If evaluation of either function throws an exception, it is relayed to the caller of the composed function.
| Parameters | |
|---|---|
| the type of output of the after function, and of the composed function | |
| after | Function<in R, out V>!: the function to apply after this function is applied |
| Return | |
|---|---|
| Function<T, V>! | a composed function that first applies this function and then applies the after function |
| Exceptions | |
|---|---|
| java.lang.NullPointerException | if after is null |
See Also
[#compose(Function)](#compose%28java.util.function.Function%29)
apply
abstract fun apply(t: T): R
Applies this function to the given argument.
| Parameters | |
|---|---|
| t | T: the function argument |
| Return | |
|---|---|
| R | the function result |
compose
open fun <V : Any!> compose(before: Function<in V, out T>!): Function<V, R>!
Returns a composed function that first applies the before function to its input, and then applies this function to the result. If evaluation of either function throws an exception, it is relayed to the caller of the composed function.
| Parameters | |
|---|---|
| the type of input to the before function, and to the composed function | |
| before | Function<in V, out T>!: the function to apply before this function is applied |
| Return | |
|---|---|
| Function<V, R>! | a composed function that first applies the before function and then applies this function |
| Exceptions | |
|---|---|
| java.lang.NullPointerException | if before is null |
See Also
[#andThen(Function)](#andThen%28java.util.function.Function%29)
identity
open static fun <T : Any!> identity(): Function<T, T>!
Returns a function that always returns its input argument.
| Parameters | |
|---|---|
| the type of the input and output objects to the function |
| Return | |
|---|---|
| Function<T, T>! | a function that always returns its input argument |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.