Package io.vavr

Interface PartialFunction<T,​R>

    • Method Summary

      Modifier and Type Method Description
      R apply​(T t)
      Applies this function to the given argument and returns the result.
      static <T,​V extends Value<T>>
      PartialFunction<V,​T>
      getIfDefined()
      Factory method for creating a partial function that maps a given Value to its underlying value.
      boolean isDefinedAt​(T value)
      Tests if a value is contained in the function's domain.
      default Function1<T,​Option<R>> lift()
      Lifts this partial function into a total function that returns an Option result.
      static <T,​R>
      PartialFunction<T,​R>
      unlift​(java.util.function.Function<? super T,​? extends Option<? extends R>> totalFunction)
      Unlifts a totalFunction that returns an Option result into a partial function.
    • Method Detail

      • unlift

        static <T,​R> PartialFunction<T,​R> unlift​(java.util.function.Function<? super T,​? extends Option<? extends R>> totalFunction)
        Unlifts a totalFunction that returns an Option result into a partial function. The total function should be side effect free because it might be invoked twice: when checking if the unlifted partial function is defined at a value and when applying the partial function to a value.
        Type Parameters:
        T - type of the function input, called domain of the function
        R - type of the function output, called codomain of the function
        Parameters:
        totalFunction - the function returning an Option result.
        Returns:
        a partial function that is not necessarily defined for all input values of type T.
      • getIfDefined

        static <T,​V extends Value<T>> PartialFunction<V,​T> getIfDefined()
        Factory method for creating a partial function that maps a given Value to its underlying value. The partial function is defined for an input Value if and only if the input Value is not empty. If the input Value is not empty, the partial function will return the underlying value of the input Value.
        Type Parameters:
        T - type of the underlying value of the input Value.
        V - type of the function input, called domain of the function
        Returns:
        a partial function that maps a Value to its underlying value.
      • apply

        R apply​(T t)
        Applies this function to the given argument and returns the result.
        Specified by:
        apply in interface java.util.function.Function<T,​R>
        Specified by:
        apply in interface Function1<T,​R>
        Parameters:
        t - the argument
        Returns:
        the result of function application
      • isDefinedAt

        boolean isDefinedAt​(T value)
        Tests if a value is contained in the function's domain.
        Parameters:
        value - a potential function argument
        Returns:
        true, if the given value is contained in the function's domain, false otherwise
      • lift

        default Function1<T,​Option<R>> lift()
        Lifts this partial function into a total function that returns an Option result.
        Returns:
        a function that applies arguments to this function and returns Some(result) if the function is defined for the given arguments, and None otherwise.