Interface PartialFunction<T,R>
- Type Parameters:
T- the type of the function input (the domain)R- the type of the function output (the codomain)
- 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
T -> R that may not be defined for all input values of type T.
The caller is responsible for checking isDefinedAt(Object) before applying this function.
If the function is not defined for a given value, apply(Object) may produce an arbitrary result.
There is no guarantee that an exception will be thrown in this case.
If the function is defined for a given value, apply(Object) may still throw an exception during execution.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe serial version UID for serialization. -
Method Summary
Modifier and TypeMethodDescriptionApplies this function to the given argument and returns the result.static <T,V extends Value<T>>
PartialFunction<V, T> Creates a partial function that maps a givenValueto its underlying value.booleanisDefinedAt(T value) Tests whether a value is contained in the function's domain.lift()Lifts this partial function into a total function that returns anOptionresult.static <T,R> PartialFunction <T, R> Converts (or "unlifts") atotalFunctionthat returns anOptioninto a partial function.
-
Field Details
-
serialVersionUID
static final long serialVersionUIDThe serial version UID for serialization.- See Also:
-
-
Method Details
-
unlift
static <T,R> PartialFunction<T,R> unlift(@NonNull Function<? super T, ? extends Option<? extends R>> totalFunction) Converts (or "unlifts") atotalFunctionthat returns anOptioninto a partial function.The provided
totalFunctionshould 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 anOptionresult- Returns:
- a partial function that is defined only for inputs for which the
totalFunctionreturns a definedOption
-
getIfDefined
Creates a partial function that maps a givenValueto its underlying value.The resulting partial function is defined for an input
Valueif and only if theValueis not empty. For defined inputs, the partial function returns the underlying value contained in theValue.- Type Parameters:
T- the type of the underlying valueV- the type of the inputValue(the domain of the function)- Returns:
- a partial function that maps a non-empty
Valueto its underlying value
-
apply
Applies this function to the given argument and returns the result. -
isDefinedAt
Tests whether a value is contained in the function's domain.- Parameters:
value- a potential input to the function- Returns:
trueif the given value is contained in the function's domain,falseotherwise
-
lift
Lifts this partial function into a total function that returns anOptionresult.The resulting function applies an argument to this partial function and returns
Some(result)if the function is defined for that argument, orNoneif it is not defined.- Returns:
- a total function that returns an
Optioncontaining the result if defined, orNoneotherwise
-