Interface Function<T,​R>

Type Parameters:
T - the type of the input to the function
R - the type of the result of the function
All Superinterfaces:
Function<T,​R>
All Known Subinterfaces:
DoubleFunction<R>, DoublePredicate, DoubleToIntFunction, DoubleToLongFunction, DoubleUnaryOperator, IntFunction<R>, IntPredicate, IntToDoubleFunction, IntToLongFunction, IntUnaryOperator, LongFunction<R>, LongPredicate, LongToDoubleFunction, LongToIntFunction, LongUnaryOperator, Predicate<T>, ToDoubleFunction<T>, ToIntFunction<T>, ToLongFunction<T>, UnaryOperator<T>
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface
public interface Function<T,​R>
extends Function<T,​R>
Represents a function that accepts one argument and produces a result.

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

Since:
1.8
  • Field Details

  • Method Details

    • apply

      R apply​(T t)
      Applies this function to the given argument.
      Specified by:
      apply in interface Function<T,​R>
      Parameters:
      t - the function argument
      Returns:
      the function result
    • applyPartial

      default Supplier<? extends R> applyPartial​(T t)
      Partially apply a parameter such that a single param function becomes a no-param supplier.
      Parameters:
      t - The parameter to apply.
      Returns:
      A partially-applied function.
    • consume

      default Consumer<T> consume​(Consumer<R> consumer)
      Consume a function.
      Parameters:
      consumer - The consumer to use in consuming.
      Returns:
      A Consumer which passes it's argument to this function and then passes the result into the given consumer.
    • map

      default <S> Function<T,​S> map​(Function<? super R,​? extends S> functor)
      Lift a function.
      Type Parameters:
      S - The return type.
      Parameters:
      functor - The function to use in lifting.
      Returns:
      A function that passes the result of fn through a functor to produce a lifted function.
    • mapToPredicate

      default Predicate<T> mapToPredicate​(Predicate<? super R> functor)
      Lift a function.
      Parameters:
      functor - The function to use in lifting.
      Returns:
      A function that passes the result of fn through a functor to produce a lifted function.
    • mapToDouble

      default ToDoubleFunction<T> mapToDouble​(ToDoubleFunction<? super R> functor)
      Lift a function.
      Parameters:
      functor - The function to use in lifting.
      Returns:
      A function that passes the result of fn through a functor to produce a lifted function.
    • mapToInt

      default ToIntFunction<T> mapToInt​(ToIntFunction<? super R> functor)
      Lift a function.
      Parameters:
      functor - The function to use in lifting.
      Returns:
      A function that passes the result of fn through a functor to produce a lifted function.
    • mapToLong

      default ToLongFunction<T> mapToLong​(ToLongFunction<? super R> functor)
      Lift a function.
      Parameters:
      functor - The function to use in lifting.
      Returns:
      A function that passes the result of fn through a functor to produce a lifted function.
    • identity

      static <T> Function<T,​T> identity()
      Returns a function that always returns its input argument.
      Type Parameters:
      T - the type of the input and output objects to the function
      Returns:
      a function that always returns its input argument