S
- the source of a POptional
T
- the modified source of a POptional
A
- the target of a POptional
B
- the modified target of a POptional
public abstract class POptional<S,T,A,B>
extends java.lang.Object
POptional
can be seen as a pair of functions:getOrModify: S => T \/ A
set : (B, S) => T
A POptional
could also be defined as a weaker PLens
and weaker PPrism
POptional
stands for Polymorphic Optional as it set and modify methods change a type A
to B
and S
to T
.
Optional
is a POptional
restricted to monomoprhic updates: type Optional[S, A] = POptional[S, S, A, A]
Modifier and Type | Method and Description |
---|---|
Fold<S,A> |
asFold()
|
PSetter<S,T,A,B> |
asSetter()
|
PTraversal<S,T,A,B> |
asTraversal()
view a
POptional as a PTraversal |
<C> Fold<S,C> |
composeFold(Fold<A,C> other)
|
<C> Fold<S,C> |
composeGetter(Getter<A,C> other)
|
<C,D> POptional<S,T,C,D> |
composeIso(PIso<A,B,C,D> other)
|
<C,D> POptional<S,T,C,D> |
composeLens(PLens<A,B,C,D> other)
|
<C,D> POptional<S,T,C,D> |
composeOptional(POptional<A,B,C,D> other)
|
<C,D> POptional<S,T,C,D> |
composePrism(PPrism<A,B,C,D> other)
|
<C,D> PSetter<S,T,C,D> |
composeSetter(PSetter<A,B,C,D> other)
|
<C,D> PTraversal<S,T,C,D> |
composeTraversal(PTraversal<A,B,C,D> other)
compose a
POptional with a PTraversal |
<C> POptional<P2<S,C>,P2<T,C>,P2<A,C>,P2<B,C>> |
first() |
abstract Option<A> |
getOption(S s)
get the target of a
POptional or nothing if there is no target |
abstract Either<T,A> |
getOrModify(S s)
get the target of a
POptional or modify the source in case there is no target |
boolean |
isMatching(S s)
check if a
POptional has a target |
abstract F<S,T> |
modify(F<A,B> f)
modify polymorphically the target of a
POptional with a function |
abstract <L> F<S,Either<L,T>> |
modifyEitherF(F<A,Either<L,B>> f)
modify polymorphically the target of a
POptional with an Applicative function |
abstract <C> F<S,F<C,T>> |
modifyFunctionF(F<A,F<C,B>> f)
modify polymorphically the target of a
POptional with an Applicative function |
abstract F<S,IO<T>> |
modifyIOF(F<A,IO<B>> f)
modify polymorphically the target of a
POptional with an Applicative function |
abstract F<S,List<T>> |
modifyListF(F<A,List<B>> f)
modify polymorphically the target of a
POptional with an Applicative function |
F<S,Option<T>> |
modifyOption(F<A,B> f)
modify polymorphically the target of a
POptional with a function. |
abstract F<S,Option<T>> |
modifyOptionF(F<A,Option<B>> f)
modify polymorphically the target of a
POptional with an Applicative function |
abstract F<S,P1<T>> |
modifyP1F(F<A,P1<B>> f)
modify polymorphically the target of a
POptional with an Applicative function |
abstract F<S,Promise<T>> |
modifyPromiseF(F<A,Promise<B>> f)
modify polymorphically the target of a
POptional with an Applicative function |
abstract F<S,Stream<T>> |
modifyStreamF(F<A,Stream<B>> f)
modify polymorphically the target of a
POptional with an Applicative function |
abstract F<S,Trampoline<T>> |
modifyTrampolineF(F<A,Trampoline<B>> f)
modify polymorphically the target of a
POptional with an Applicative function |
abstract F<S,V2<T>> |
modifyV2F(F<A,V2<B>> f)
modify polymorphically the target of a
POptional with an Applicative function |
abstract <E> F<S,Validation<E,T>> |
modifyValidationF(F<A,Validation<E,B>> f)
modify polymorphically the target of a
POptional with an Applicative function |
static <S,T> POptional<S,T,S,T> |
pId() |
static <S,T,A,B> POptional<S,T,A,B> |
pOptional(F<S,Either<T,A>> getOrModify,
F<B,F<S,T>> set)
create a
POptional using the canonical functions: getOrModify and set |
<C> POptional<P2<C,S>,P2<C,T>,P2<C,A>,P2<C,B>> |
second() |
abstract F<S,T> |
set(B b)
get the modified source of a
POptional |
F<S,Option<T>> |
setOption(B b)
set polymorphically the target of a
POptional with a value. |
<S1,T1> POptional<Either<S,S1>,Either<T,T1>,A,B> |
sum(POptional<S1,T1,A,B> other)
join two
POptional with the same target |
public abstract Either<T,A> getOrModify(S s)
POptional
or modify the source in case there is no targetpublic abstract Option<A> getOption(S s)
POptional
or nothing if there is no targetpublic abstract <C> F<S,F<C,T>> modifyFunctionF(F<A,F<C,B>> f)
POptional
with an Applicative functionpublic abstract <L> F<S,Either<L,T>> modifyEitherF(F<A,Either<L,B>> f)
POptional
with an Applicative functionpublic abstract F<S,IO<T>> modifyIOF(F<A,IO<B>> f)
POptional
with an Applicative functionpublic abstract F<S,Trampoline<T>> modifyTrampolineF(F<A,Trampoline<B>> f)
POptional
with an Applicative functionpublic abstract F<S,Promise<T>> modifyPromiseF(F<A,Promise<B>> f)
POptional
with an Applicative functionpublic abstract F<S,List<T>> modifyListF(F<A,List<B>> f)
POptional
with an Applicative functionpublic abstract F<S,Option<T>> modifyOptionF(F<A,Option<B>> f)
POptional
with an Applicative functionpublic abstract F<S,Stream<T>> modifyStreamF(F<A,Stream<B>> f)
POptional
with an Applicative functionpublic abstract F<S,P1<T>> modifyP1F(F<A,P1<B>> f)
POptional
with an Applicative functionpublic abstract <E> F<S,Validation<E,T>> modifyValidationF(F<A,Validation<E,B>> f)
POptional
with an Applicative functionpublic abstract F<S,V2<T>> modifyV2F(F<A,V2<B>> f)
POptional
with an Applicative functionpublic abstract F<S,T> modify(F<A,B> f)
POptional
with a functionpublic final <S1,T1> POptional<Either<S,S1>,Either<T,T1>,A,B> sum(POptional<S1,T1,A,B> other)
POptional
with the same targetpublic final <C,D> PTraversal<S,T,C,D> composeTraversal(PTraversal<A,B,C,D> other)
POptional
with a PTraversal
public PTraversal<S,T,A,B> asTraversal()
POptional
as a PTraversal
public static <S,T> POptional<S,T,S,T> pId()