Package io.vavr

Interface PartialFunction<T,​R>

    • Field Detail

      • serialVersionUID

        static final long serialVersionUID
        The serial version UID for serialization.
        See Also:
        Constant Field Values
    • Method Detail

      • unlift

        static <T,​R> PartialFunction<T,​R> unlift​(@NonNull java.util.function.Function<? super T,​? extends Option<? extends R>> totalFunction)
        Converts (or "unlifts") a totalFunction that returns an Option into a partial function.

        The provided totalFunction should be side-effect-free, because it may be invoked twice: once when checking if the resulting partial function is defined at a value, and once when applying the partial function to that value.

        Type Parameters:
        T - the type of the function input (the domain)
        R - the type of the function output (the codomain)
        Parameters:
        totalFunction - the function returning an Option result
        Returns:
        a partial function that is defined only for inputs for which the totalFunction returns a defined Option
      • getIfDefined

        static <T,​V extends Value<T>> PartialFunction<V,​T> getIfDefined()
        Creates a partial function that maps a given Value to its underlying value.

        The resulting partial function is defined for an input Value if and only if the Value is not empty. For defined inputs, the partial function returns the underlying value contained in the Value.

        Type Parameters:
        T - the type of the underlying value
        V - the type of the input Value (the domain of the function)
        Returns:
        a partial function that maps a non-empty 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 input argument
        Returns:
        the result of applying this function to the input
      • isDefinedAt

        boolean isDefinedAt​(T value)
        Tests whether a value is contained in the function's domain.
        Parameters:
        value - a potential input to the function
        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.

        The resulting function applies an argument to this partial function and returns Some(result) if the function is defined for that argument, or None if it is not defined.

        Returns:
        a total function that returns an Option containing the result if defined, or None otherwise