Top Description Fields Methods
io.vavr

public Interface PartialFunction<T, R>

extends Function1<T, R>
Known Direct Subinterfaces
io.vavr.collection.Map, io.vavr.collection.Multimap, io.vavr.collection.Seq, io.vavr.API.Match.Case, io.vavr.API.Match.Pattern
Type Parameters
<T>
type of the function input, called domain of the function
<R>
type of the function output, called codomain of the function
Imports
io.vavr.control.Option, java.util.function.Function

Represents a partial function T -> R that is not necessarily defined for all input values of type T. The caller is responsible for calling the method isDefinedAt() before this function is applied to the value.

If the function is not defined for a specific value, apply() may produce an arbitrary result. More specifically it is not guaranteed that the function will throw an exception.

If the function is defined for a specific value, apply() may still throw an exception.

Author
Daniel Dietrich

Field Summary

Modifier and TypeField and Description
public static final long

Method Summary

Modifier and TypeMethod and Description
public R

Returns:

the result of function application
apply
(T
the argument
t
)

Redeclares io.vavr.Function1.apply.

Applies this function to the given argument and returns the result.

public static <
type of the underlying value of the input Value.
T
,
type of the function input, called domain of the function
V extends Value<T>
>
PartialFunction<V, T>

Returns:

a partial function that maps a Value to its underlying value.
getIfDefined
()

Factory method for creating a partial function that maps a given Value to its underlying value.

public boolean

Returns:

true, if the given value is contained in the function's domain, false otherwise
isDefinedAt
(T
a potential function argument
value
)

Tests if a value is contained in the function's domain.

public default Function1<T, Option<R>>

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.
lift
()

Lifts this partial function into a total function that returns an Option result.

public static <
type of the function input, called domain of the function
T
,
type of the function output, called codomain of the function
R
>
PartialFunction<T, R>

Returns:

a partial function that is not necessarily defined for all input values of type T.
unlift
(Function<? super T, ? extends Option<? extends R>>
the function returning an Option result.
totalFunction
)

Unlifts a totalFunction that returns an Option result into a partial function.

Inherited from io.vavr.Function1:
andThenaritycomposeconstantcurriedidentityisMemoizedliftliftTrymemoizednarrowofpartialreversedtupled

Field Detail

serialVersionUIDback to summary
public static final long serialVersionUID

Hides io.vavr.Function1.serialVersionUID.

The serial version uid.

Method Detail

applyback to summary
public R apply(T t)

Redeclares io.vavr.Function1.apply.

Applies this function to the given argument and returns the result.

Parameters
t:T

the argument

Returns:R

the result of function application

getIfDefinedback to summary
public 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.

Parameters
<T>
type of the underlying value of the input Value.
<V>
type of the function input, called domain of the function
Returns:PartialFunction<V, T>

a partial function that maps a Value to its underlying value.

isDefinedAtback to summary
public boolean isDefinedAt(T value)

Tests if a value is contained in the function's domain.

Parameters
value:T

a potential function argument

Returns:boolean

true, if the given value is contained in the function's domain, false otherwise

liftback to summary
public default Function1<T, Option<R>> lift()

Lifts this partial function into a total function that returns an Option result.

Returns:Function1<T, Option<R>>

a function that applies arguments to this function and returns Some(result) if the function is defined for the given arguments, and None otherwise.

unliftback to summary
public static <T, R> PartialFunction<T, R> unlift(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.

Parameters
<T>
type of the function input, called domain of the function
<R>
type of the function output, called codomain of the function
totalFunction:Function<? super T, ? extends Option<? extends R>>

the function returning an Option result.

Returns:PartialFunction<T, R>

a partial function that is not necessarily defined for all input values of type T.