# Function

Added in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Methods](https://developer.android.com/reference/java/util/function/Function#pubmethods)  

# Function

`
public


interface
Function
`  
`


`

|-------------------------------------|
| java.util.function.Function\<T, R\> |

|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Known indirect subclasses [UnaryOperator](https://developer.android.com/reference/java/util/function/UnaryOperator)\<T\> |------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------| | [UnaryOperator](https://developer.android.com/reference/java/util/function/UnaryOperator)\<T\> | Represents an operation on a single operand that produces a result of the same type as its operand. | |

<br />

*** ** * ** ***

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

This is a[functional interface](https://developer.android.com/reference/java/util/function/package-summary)whose functional method is[apply(java.lang.Object)](https://developer.android.com/reference/java/util/function/Function#apply(T)).

## Summary

|                                                                                                                                                                                                                                                ### Public methods                                                                                                                                                                                                                                                 ||
|--------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` default <V> `[Function](https://developer.android.com/reference/java/util/function/Function)`<T, V>` | ` `[andThen](https://developer.android.com/reference/java/util/function/Function#andThen(java.util.function.Function<?%20super%20R,?%20extends%20V>))`(`[Function](https://developer.android.com/reference/java/util/function/Function)`<? super R, ? extends V> after) ` Returns a composed function that first applies this function to its input, and then applies the`after`function to the result.   |
| ` abstract R`                                                                                          | ` `[apply](https://developer.android.com/reference/java/util/function/Function#apply(T))`(T t) ` Applies this function to the given argument.                                                                                                                                                                                                                                                             |
| ` default <V> `[Function](https://developer.android.com/reference/java/util/function/Function)`<V, R>` | ` `[compose](https://developer.android.com/reference/java/util/function/Function#compose(java.util.function.Function<?%20super%20V,?%20extends%20T>))`(`[Function](https://developer.android.com/reference/java/util/function/Function)`<? super V, ? extends T> before) ` Returns a composed function that first applies the`before`function to its input, and then applies this function to the result. |
| ` static <T> `[Function](https://developer.android.com/reference/java/util/function/Function)`<T, T>`  | ` `[identity](https://developer.android.com/reference/java/util/function/Function#identity())`() ` Returns a function that always returns its input argument.                                                                                                                                                                                                                                             |

## Public methods

### andThen

Added in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Function<T, V> andThen (Function<? super R, ? extends V> after)
```

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.

<br />

|                                    Parameters                                    ||
|---------|-------------------------------------------------------------------------|
| `after` | `Function`: the function to apply after this function is applied <br /> |

|                                                                                         Returns                                                                                          ||
|-----------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------|
| [Function](https://developer.android.com/reference/java/util/function/Function)`<T, V>` | a composed function that first applies this function and then applies the`after`function <br /> |

|                                                      Throws                                                      ||
|------------------------------------------------------------------------------------------------|------------------|
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException) | if after is null |

**See also:**

- [compose(Function)](https://developer.android.com/reference/java/util/function/Function#compose(java.util.function.Function<?%20super%20V,?%20extends%20T>))  

### apply

Added in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract R apply (T t)
```

Applies this function to the given argument.

<br />

|               Parameters               ||
|-----|-----------------------------------|
| `t` | `T`: the function argument <br /> |

|             Returns             ||
|-----|----------------------------|
| `R` | the function result <br /> |

### compose

Added in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Function<V, R> compose (Function<? super V, ? extends T> before)
```

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.

<br />

|                                     Parameters                                     ||
|----------|--------------------------------------------------------------------------|
| `before` | `Function`: the function to apply before this function is applied <br /> |

|                                                                                          Returns                                                                                          ||
|-----------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------|
| [Function](https://developer.android.com/reference/java/util/function/Function)`<V, R>` | a composed function that first applies the`before`function and then applies this function <br /> |

|                                                      Throws                                                       ||
|------------------------------------------------------------------------------------------------|-------------------|
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException) | if before is null |

**See also:**

- [andThen(Function)](https://developer.android.com/reference/java/util/function/Function#andThen(java.util.function.Function<?%20super%20R,?%20extends%20V>))  

### identity

Added in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static Function<T, T> identity ()
```

Returns a function that always returns its input argument.

<br />

|                                                                      Returns                                                                      ||
|-----------------------------------------------------------------------------------------|----------------------------------------------------------|
| [Function](https://developer.android.com/reference/java/util/function/Function)`<T, T>` | a function that always returns its input argument <br /> |