Package fj.data.optic
Class PPrism<S,T,A,B>
- java.lang.Object
-
- fj.data.optic.PPrism<S,T,A,B>
-
- Type Parameters:
S
- the source of aPPrism
T
- the modified source of aPPrism
A
- the target of aPPrism
B
- the modified target of aPPrism
- Direct Known Subclasses:
Prism
public abstract class PPrism<S,T,A,B> extends java.lang.Object
APPrism
can be seen as a pair of functions:getOrModify: S => T \/ A
reverseGet : B => T
A
PPrism
could also be defined as a weakerPIso
where get can fail.Typically a
PPrism
orPrism
encodes the relation between a Sum or CoProduct type (e.g. sealed trait) and one of it is element.PPrism
stands for Polymorphic Prism as it set and modify methods change a typeA
toB
andS
toT
.Prism
is aPPrism
where the type of target cannot be modified. APPrism
is also a validFold
,POptional
,PTraversal
andPSetter
-
-
Constructor Summary
Constructors Constructor Description PPrism()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Fold<S,A>
asFold()
POptional<S,T,A,B>
asOptional()
PSetter<S,T,A,B>
asSetter()
PTraversal<S,T,A,B>
asTraversal()
view aPPrism
as aPTraversal
<C> Fold<S,C>
composeFold(Fold<A,C> other)
<C> Fold<S,C>
composeGetter(Getter<A,C> other)
<C,D>
PPrism<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>
PPrism<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 aPPrism
with aPTraversal
abstract Option<A>
getOption(S s)
get the target of aPPrism
or nothing if there is no targetabstract Either<T,A>
getOrModify(S s)
get the target of aPPrism
or modify the source in case there is no targetboolean
isMatching(S s)
check if aPPrism
has a targetF<S,T>
modify(F<A,B> f)
modify polymorphically the target of aPPrism
with a function<L> F<S,Either<L,T>>
modifyEitherF(F<A,Either<L,B>> f)
modify polymorphically the target of aPPrism
with an Applicative function<C> F<S,F<C,T>>
modifyFunctionF(F<A,F<C,B>> f)
modify polymorphically the target of aPPrism
with an Applicative functionF<S,IO<T>>
modifyIOF(F<A,IO<B>> f)
modify polymorphically the target of aPPrism
with an Applicative functionF<S,List<T>>
modifyListF(F<A,List<B>> f)
modify polymorphically the target of aPPrism
with an Applicative functionF<S,Option<T>>
modifyOption(F<A,B> f)
modify polymorphically the target of aPPrism
with a function.F<S,Option<T>>
modifyOptionF(F<A,Option<B>> f)
modify polymorphically the target of aPPrism
with an Applicative functionF<S,P1<T>>
modifyP1F(F<A,P1<B>> f)
modify polymorphically the target of aPPrism
with an Applicative functionF<S,Promise<T>>
modifyPromiseF(F<A,Promise<B>> f)
modify polymorphically the target of aPPrism
with an Applicative functionF<S,Stream<T>>
modifyStreamF(F<A,Stream<B>> f)
modify polymorphically the target of aPPrism
with an Applicative functionF<S,Trampoline<T>>
modifyTrampolineF(F<A,Trampoline<B>> f)
modify polymorphically the target of aPPrism
with an Applicative functionF<S,V2<T>>
modifyV2F(F<A,V2<B>> f)
modify polymorphically the target of aPPrism
with an Applicative function<E> F<S,Validation<E,T>>
modifyValidationF(F<A,Validation<E,B>> f)
modify polymorphically the target of aPPrism
with an Applicative functionstatic <S,T>
PPrism<S,T,S,T>pId()
static <S,T,A,B>
PPrism<S,T,A,B>pPrism(F<S,Either<T,A>> getOrModify, F<B,T> reverseGet)
create aPPrism
using the canonical functions: getOrModify and reverseGetGetter<B,T>
re()
abstract T
reverseGet(B b)
get the modified source of aPPrism
F<S,T>
set(B b)
set polymorphically the target of aPPrism
with a valueF<S,Option<T>>
setOption(B b)
set polymorphically the target of aPPrism
with a value.
-
-
-
Method Detail
-
getOrModify
public abstract Either<T,A> getOrModify(S s)
get the target of aPPrism
or modify the source in case there is no target
-
getOption
public abstract Option<A> getOption(S s)
get the target of aPPrism
or nothing if there is no target
-
modifyFunctionF
public final <C> F<S,F<C,T>> modifyFunctionF(F<A,F<C,B>> f)
modify polymorphically the target of aPPrism
with an Applicative function
-
modifyEitherF
public final <L> F<S,Either<L,T>> modifyEitherF(F<A,Either<L,B>> f)
modify polymorphically the target of aPPrism
with an Applicative function
-
modifyIOF
public final F<S,IO<T>> modifyIOF(F<A,IO<B>> f)
modify polymorphically the target of aPPrism
with an Applicative function
-
modifyTrampolineF
public final F<S,Trampoline<T>> modifyTrampolineF(F<A,Trampoline<B>> f)
modify polymorphically the target of aPPrism
with an Applicative function
-
modifyPromiseF
public final F<S,Promise<T>> modifyPromiseF(F<A,Promise<B>> f)
modify polymorphically the target of aPPrism
with an Applicative function
-
modifyListF
public final F<S,List<T>> modifyListF(F<A,List<B>> f)
modify polymorphically the target of aPPrism
with an Applicative function
-
modifyOptionF
public final F<S,Option<T>> modifyOptionF(F<A,Option<B>> f)
modify polymorphically the target of aPPrism
with an Applicative function
-
modifyStreamF
public final F<S,Stream<T>> modifyStreamF(F<A,Stream<B>> f)
modify polymorphically the target of aPPrism
with an Applicative function
-
modifyP1F
public final F<S,P1<T>> modifyP1F(F<A,P1<B>> f)
modify polymorphically the target of aPPrism
with an Applicative function
-
modifyValidationF
public final <E> F<S,Validation<E,T>> modifyValidationF(F<A,Validation<E,B>> f)
modify polymorphically the target of aPPrism
with an Applicative function
-
modifyV2F
public final F<S,V2<T>> modifyV2F(F<A,V2<B>> f)
modify polymorphically the target of aPPrism
with an Applicative function
-
modify
public final F<S,T> modify(F<A,B> f)
modify polymorphically the target of aPPrism
with a function
-
composeTraversal
public final <C,D> PTraversal<S,T,C,D> composeTraversal(PTraversal<A,B,C,D> other)
compose aPPrism
with aPTraversal
-
composeOptional
public final <C,D> POptional<S,T,C,D> composeOptional(POptional<A,B,C,D> other)
-
asTraversal
public PTraversal<S,T,A,B> asTraversal()
view aPPrism
as aPTraversal
-
pId
public static <S,T> PPrism<S,T,S,T> pId()
-
-