Interface ToObjectFunction<T,R>

Type Parameters:
T - the input type
R - the return type
All Superinterfaces:
Function<T,R>, TypedFunction<T>

public interface ToObjectFunction<T,R> extends TypedFunction<T>, Function<T,R>
An object function.

Note: this is not a FunctionalInterface, as returnType() must be provided.

  • Method Details

    • of

      static <T, R> ToObjectFunction<T,R> of(Function<? super T,? extends R> f, GenericType<R> returnType)
      Creates an object function from f and returnType.
      Type Parameters:
      T - the input type
      R - the return type
      Parameters:
      f - the function
      returnType - the return type
      Returns:
      the object function
    • identity

      static <T> ToObjectFunction<T,Object> identity()
      Creates an object function that casts each input to Object. Equivalent to x -> (Object)x.
      Type Parameters:
      T - the input type
      Returns:
      the object function
    • identity

      static <T, R extends T> ToObjectFunction<T,R> identity(GenericType<R> returnType)
      Creates an object function that casts each input to returnType. Equivalent to x -> (R)x.
      Type Parameters:
      T - the input type
      R - the return type
      Parameters:
      returnType - the return type
      Returns:
      the object function
    • map

      static <T, R, Z> ToObjectFunction<T,Z> map(Function<? super T,? extends R> f, ToObjectFunction<? super R,Z> g)
      Creates the function composition g ∘ f.

      Equivalent to x -> g.apply(f.apply(x)).

      Type Parameters:
      T - the input type
      R - the intermediate type
      Z - the return type
      Parameters:
      f - the inner function
      g - the outer function
      Returns:
      the object function
    • map

      static <T, R, Z> ToObjectFunction<T,Z> map(Function<? super T,? extends R> f, Function<? super R,? extends Z> g, GenericType<Z> returnType)
      Creates the function composition g ∘ f.

      Equivalent to x -> g.apply(f.apply(x)).

      Type Parameters:
      T - the input type
      R - the intermediate type
      Z - the return type
      Parameters:
      f - the inner function
      g - the outer function
      returnType - the return type
      Returns:
      the object function
    • returnType

      GenericType<R> returnType()
      Description copied from interface: TypedFunction
      This function's return type.
      Specified by:
      returnType in interface TypedFunction<T>
      Returns:
      the type
    • apply

      R apply(T value)
      Specified by:
      apply in interface Function<T,R>
    • mapToBoolean

      default <T2 extends T> ToBooleanFunction<T2> mapToBoolean(Predicate<? super R> g)
      Creates the function composition g ∘ this.

      Equivalent to x -> g.test(this.apply(x)).

      Type Parameters:
      T2 - the returned function input type
      Parameters:
      g - the outer function
      Returns:
      the boolean function
    • mapToChar

      default <T2 extends T> ToCharFunction<T2> mapToChar(ToCharFunction<? super R> g)
      Creates the function composition g ∘ this.

      Equivalent to x -> g.applyAsChar(this.apply(x)).

      Type Parameters:
      T2 - the returned function input type
      Parameters:
      g - the outer function
      Returns:
      the char function
    • mapToByte

      default <T2 extends T> ToByteFunction<T2> mapToByte(ToByteFunction<? super R> g)
      Creates the function composition g ∘ this.

      Equivalent to x -> g.applyAsByte(this.apply(x)).

      Type Parameters:
      T2 - the returned function input type
      Parameters:
      g - the outer function
      Returns:
      the byte function
    • mapToShort

      default <T2 extends T> ToShortFunction<T2> mapToShort(ToShortFunction<? super R> g)
      Creates the function composition g ∘ this.

      Equivalent to x -> g.applyAsShort(this.apply(x)).

      Type Parameters:
      T2 - the returned function input type
      Parameters:
      g - the outer function
      Returns:
      the short function
    • mapToInt

      default <T2 extends T> ToIntFunction<T2> mapToInt(ToIntFunction<? super R> g)
      Creates the function composition g ∘ this.

      Equivalent to x -> g.applyAsInt(this.apply(x)).

      Type Parameters:
      T2 - the returned function input type
      Parameters:
      g - the outer function
      Returns:
      the int function
    • mapToLong

      default <T2 extends T> ToLongFunction<T2> mapToLong(ToLongFunction<? super R> g)
      Creates the function composition g ∘ this.

      Equivalent to x -> g.applyAsLong(this.apply(x)).

      Type Parameters:
      T2 - the returned function input type
      Parameters:
      g - the outer function
      Returns:
      the long function
    • mapToFloat

      default <T2 extends T> ToFloatFunction<T2> mapToFloat(ToFloatFunction<? super R> g)
      Creates the function composition g ∘ this.

      Equivalent to x -> g.applyAsFloat(this.apply(x)).

      Type Parameters:
      T2 - the returned function input type
      Parameters:
      g - the outer function
      Returns:
      the float function
    • mapToDouble

      default <T2 extends T> ToDoubleFunction<T2> mapToDouble(ToDoubleFunction<? super R> g)
      Creates the function composition g ∘ this.

      Equivalent to x -> g.applyAsDouble(this.apply(x)).

      Type Parameters:
      T2 - the returned function input type
      Parameters:
      g - the outer function
      Returns:
      the double function
    • mapToObj

      default <T2 extends T, R2> ToObjectFunction<T2,R2> mapToObj(ToObjectFunction<? super R,R2> g)
      Creates the function composition g ∘ this.

      Equivalent to x -> g.apply(this.apply(x)).

      Type Parameters:
      T2 - the returned function input type
      R2 - the returned function return type
      Parameters:
      g - the outer function
      Returns:
      the object function
    • mapToObj

      default <T2 extends T, R2> ToObjectFunction<T2,R2> mapToObj(Function<? super R,? extends R2> g, GenericType<R2> returnType)
      Creates the function composition g ∘ this.

      Equivalent to x -> g.apply(this.apply(x)).

      Type Parameters:
      T2 - the returned function input type
      R2 - the returned function return type
      Parameters:
      g - the outer function
      Returns:
      the object function
    • mapToPrimitive

      default <T2 extends T> ToPrimitiveFunction<T2> mapToPrimitive(ToPrimitiveFunction<? super R> g)
      Creates the function composition g ∘ this.

      Prefer to call one of the more strongly-typed map methods if you have a more specific function type.

      Type Parameters:
      T2 - the returned function input type
      Parameters:
      g - the outer function
      Returns:
      the function
      See Also:
    • map

      default <T2 extends T> TypedFunction<T2> map(TypedFunction<? super R> g)
      Creates the function composition g ∘ this.

      Prefer to call one of the more strongly-typed map methods if you have a more specific function type.

      Type Parameters:
      T2 - the returned function input type
      Parameters:
      g - the outer function
      Returns:
      the function
      See Also:
    • cast

      default <T2 extends T, R2> ToObjectFunction<T2,R2> cast(GenericType<R2> returnType)
      Creates a function by casting to returnType.

      In the case where returnType().equals(returnType), the result is (ObjectFunction<T2, R2>) this. Otherwise, the result is equivalent to x -> (R2) this.apply(x).

      Type Parameters:
      T2 - the returned function input type
      R2 - the returned function return type
      Parameters:
      returnType - the return type
      Returns:
      the object function
    • walk

      default <Z> Z walk(TypedFunction.Visitor<T,Z> visitor)
      Specified by:
      walk in interface TypedFunction<T>