Added in API level 24

Function

@FunctionalInterface interface Function<T : Any!, R : Any!>
java.util.function.Function

Represents a function that accepts one argument and produces a result.

This is a functional interface whose functional method is apply(java.lang.Object).

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>!

Returns a function that always returns its input argument.

Public methods

andThen

Added in API level 24
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
<V> 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

apply

Added in API level 24
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

Added in API level 24
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
<V> 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

identity

Added in API level 24
open static fun <T : Any!> identity(): Function<T, T>!

Returns a function that always returns its input argument.

Parameters
<T> the type of the input and output objects to the function
Return
Function<T, T>! a function that always returns its input argument