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:
java.util.function.Function<T,R>
,Function1<T,R>
,java.io.Serializable
- All Known Subinterfaces:
API.Match.Case<T,R>
,API.Match.Pattern<T,R>
,IndexedSeq<T>
,LinearSeq<T>
,Map<K,V>
,Multimap<K,V>
,Seq<T>
,SortedMap<K,V>
,SortedMultimap<K,V>
- All Known Implementing Classes:
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
,List.Cons
,List.Nil
,Queue
,Stream
,Stream.Cons
,Stream.Empty
,TreeMap
,TreeMultimap
,Vector
public interface PartialFunction<T,R> extends Function1<T,R>
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 Modifier and Type Field Description static long
serialVersionUID
The serial version uid.
-
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 givenValue
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 anOption
result.static <T,R>
PartialFunction<T,R>unlift(java.util.function.Function<? super T,? extends Option<? extends R>> totalFunction)
Unlifts atotalFunction
that returns anOption
result into a partial function.
-
-
-
Field Detail
-
serialVersionUID
static final long serialVersionUID
The serial version uid.- See Also:
- Constant Field Values
-
-
Method Detail
-
unlift
static <T,R> PartialFunction<T,R> unlift(java.util.function.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
static <T,V extends Value<T>> PartialFunction<V,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.
-
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
-
-