Function
Stay organized with collections
Save and categorize content based on your preferences.
Known Indirect Subclasses
UnaryOperator<T> |
Represents an operation on a single operand that produces a result of the
same type as its operand. |
|
Public Method Summary
<V>
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.
|
abstract
R
|
apply(T t)
Applies this function to the given argument.
|
<V>
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.
|
static
<T>
Function<T, T>
|
identity()
Returns a function that always returns its input argument.
|
Public Methods
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.
Parameters
after |
the function to apply after this function is applied |
Returns
- a composed function that first applies this function and then
applies the
after
function
public
abstract
R
apply
(T t)
Applies this function to the given argument.
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.
Parameters
before |
the function to apply before this function is applied |
Returns
- a composed function that first applies the
before
function and then applies this function
public
static
Function<T, T>
identity
()
Returns a function that always returns its input argument.
Returns
- a function that always returns its input argument
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003e\u003ccode\u003eFunction\u003c/code\u003e is a functional interface representing a function accepting one argument and producing a result.\u003c/p\u003e\n"],["\u003cp\u003eIt includes methods like \u003ccode\u003eapply\u003c/code\u003e, which executes the function on an argument, and \u003ccode\u003ecompose\u003c/code\u003e/\u003ccode\u003eandThen\u003c/code\u003e for chaining functions.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eidentity\u003c/code\u003e is a static method that returns a function returning its input unchanged.\u003c/p\u003e\n"]]],["The `Function` interface represents a function taking one argument and producing a result. Key actions include `apply(T t)`, which applies the function to a given argument. `andThen` composes a function that applies the current function, then another (`after`). `compose` composes a function that applies another function (`before`), then the current function. `identity` returns a function that mirrors its input. `UnaryOperator` is a known subclass.\n"],null,["# Function\n\npublic interface **Function** \n\n|---|---|---|\n| Known Indirect Subclasses [UnaryOperator](../../../../reference/java/util/function/UnaryOperator.html)\\\u003cT\\\u003e |-----------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------| | [UnaryOperator](../../../../reference/java/util/function/UnaryOperator.html)\\\u003cT\\\u003e | Represents an operation on a single operand that produces a result of the same type as its operand. | |||\n\nRepresents a function that accepts one argument and produces a result.\n\nThis is a [functional interface](/j2objc/javadoc/jre/reference/java/util/function/package-summary)\nwhose functional method is [apply(Object)](../../../../reference/java/util/function/Function.html#apply(T)). \n\n### Public Method Summary\n\n|-----------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| \\\u003cV\\\u003e [Function](../../../../reference/java/util/function/Function.html)\\\u003cT, V\\\u003e | [andThen](../../../../reference/java/util/function/Function.html#andThen(java.util.function.Function\u003c?%20super%20R,%20?%20extends%20V\u003e))([Function](../../../../reference/java/util/function/Function.html)\\\u003c? super R, ? extends V\\\u003e after) Returns a composed function that first applies this function to its input, and then applies the `after` function to the result. |\n| abstract R | [apply](../../../../reference/java/util/function/Function.html#apply(T))(T t) Applies this function to the given argument. |\n| \\\u003cV\\\u003e [Function](../../../../reference/java/util/function/Function.html)\\\u003cV, R\\\u003e | [compose](../../../../reference/java/util/function/Function.html#compose(java.util.function.Function\u003c?%20super%20V,%20?%20extends%20T\u003e))([Function](../../../../reference/java/util/function/Function.html)\\\u003c? super V, ? extends T\\\u003e before) Returns a composed function that first applies the `before` function to its input, and then applies this function to the result. |\n| static \\\u003cT\\\u003e [Function](../../../../reference/java/util/function/Function.html)\\\u003cT, T\\\u003e | [identity](../../../../reference/java/util/function/Function.html#identity())() Returns a function that always returns its input argument. |\n\nPublic Methods\n--------------\n\n#### public [Function](../../../../reference/java/util/function/Function.html)\\\u003cT, V\\\u003e\n**andThen**\n([Function](../../../../reference/java/util/function/Function.html)\\\u003c? super R, ? extends V\\\u003e after)\n\nReturns a composed function that first applies this function to\nits input, and then applies the `after` function to the result.\nIf evaluation of either function throws an exception, it is relayed to\nthe caller of the composed function. \n\n##### Parameters\n\n| after | the function to apply after this function is applied |\n|-------|------------------------------------------------------|\n\n##### Returns\n\n- a composed function that first applies this function and then applies the `after` function \n\n##### Throws\n\n| [NullPointerException](../../../../reference/java/lang/NullPointerException.html) | if after is null |\n|-----------------------------------------------------------------------------------|------------------|\n\n##### See Also\n\n- [compose(Function)](../../../../reference/java/util/function/Function.html#compose(java.util.function.Function\u003c?%20super%20V,%20?%20extends%20T\u003e)) \n\n#### public abstract R\n**apply**\n(T t)\n\nApplies this function to the given argument. \n\n##### Parameters\n\n| t | the function argument |\n|---|-----------------------|\n\n##### Returns\n\n- the function result \n\n#### public [Function](../../../../reference/java/util/function/Function.html)\\\u003cV, R\\\u003e\n**compose**\n([Function](../../../../reference/java/util/function/Function.html)\\\u003c? super V, ? extends T\\\u003e before)\n\nReturns a composed function that first applies the `before`\nfunction to its input, and then applies this function to the result.\nIf evaluation of either function throws an exception, it is relayed to\nthe caller of the composed function. \n\n##### Parameters\n\n| before | the function to apply before this function is applied |\n|--------|-------------------------------------------------------|\n\n##### Returns\n\n- a composed function that first applies the `before` function and then applies this function \n\n##### Throws\n\n| [NullPointerException](../../../../reference/java/lang/NullPointerException.html) | if before is null |\n|-----------------------------------------------------------------------------------|-------------------|\n\n##### See Also\n\n- [andThen(Function)](../../../../reference/java/util/function/Function.html#andThen(java.util.function.Function\u003c?%20super%20R,%20?%20extends%20V\u003e)) \n\n#### public static [Function](../../../../reference/java/util/function/Function.html)\\\u003cT, T\\\u003e\n**identity**\n()\n\nReturns a function that always returns its input argument. \n\n##### Returns\n\n- a function that always returns its input argument"]]