Package io.vavr
Interface PartialFunction<T,R>
- Type Parameters:
T
- type of the function input, called domain of the functionR
- type of the function output, called codomain of the function
- All Superinterfaces:
Function<T,
,R> Function1<T,
,R> Serializable
- All Known Subinterfaces:
API.Match.Case<T,
,R> API.Match.Pattern<T,
,R> IndexedSeq<T>
,LinearSeq<T>
,List<T>
,Map<K,
,V> Multimap<K,
,V> Seq<T>
,SortedMap<K,
,V> SortedMultimap<K,
,V> Stream<T>
- All Known Implementing Classes:
AbstractMultimap
,API.Match.Case0
,API.Match.Case1
,API.Match.Case2
,API.Match.Case3
,API.Match.Case4
,API.Match.Case5
,API.Match.Case6
,API.Match.Case7
,API.Match.Case8
,API.Match.Pattern0
,API.Match.Pattern1
,API.Match.Pattern2
,API.Match.Pattern3
,API.Match.Pattern4
,API.Match.Pattern5
,API.Match.Pattern6
,API.Match.Pattern7
,API.Match.Pattern8
,Array
,CharSeq
,HashMap
,HashMultimap
,LinkedHashMap
,LinkedHashMultimap
,List.Cons
,List.Nil
,Queue
,Stream.Cons
,Stream.Empty
,StreamModule.AppendElements
,StreamModule.ConsImpl
,TreeMap
,TreeMultimap
,Vector
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.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionApplies this function to the given argument and returns the result.static <T,
V extends Value<T>>
PartialFunction<V, T> Factory method for creating a partial function that maps a givenValue
to its underlying value.boolean
isDefinedAt
(T value) Tests if a value is contained in the function's domain.lift()
Lifts this partial function into a total function that returns anOption
result.static <T,
R> PartialFunction <T, R> Unlifts atotalFunction
that returns anOption
result into a partial function.
-
Field Details
-
serialVersionUID
static final long serialVersionUIDThe serial version uid.- See Also:
-
-
Method Details
-
unlift
static <T,R> PartialFunction<T,R> unlift(Function<? super T, ? extends Option<? extends R>> totalFunction) Unlifts atotalFunction
that returns anOption
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 functionR
- type of the function output, called codomain of the function- Parameters:
totalFunction
- the function returning anOption
result.- Returns:
- a partial function that is not necessarily defined for all input values of type T.
-
getIfDefined
Factory method for creating a partial function that maps a givenValue
to its underlying value. The partial function is defined for an inputValue
if and only if the inputValue
is not empty. If the inputValue
is not empty, the partial function will return the underlying value of the inputValue
.- Type Parameters:
T
- type of the underlying value of the inputValue
.V
- type of the function input, called domain of the function- Returns:
- a partial function that maps a
Value
to its underlying value.
-
apply
Applies this function to the given argument and returns the result. -
isDefinedAt
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
Lifts this partial function into a total function that returns anOption
result.- Returns:
- a function that applies arguments to this function and returns
Some(result)
if the function is defined for the given arguments, andNone
otherwise.
-