Interface Prism<S,T,A,B>
-
- Type Parameters:
S- the input that might fail to map to its outputT- the guaranteed outputA- the output that might fail to be producedB- the input that guarantees its output
- All Superinterfaces:
Applicative<T,Prism<S,?,A,B>>,Contravariant<S,Profunctor<?,T,Prism<?,?,A,B>>>,Functor<T,Prism<S,?,A,B>>,Monad<T,Prism<S,?,A,B>>,MonadRec<T,Prism<S,?,A,B>>,Optic<Cocartesian<?,?,?>,Identity<?>,S,T,A,B>,Profunctor<S,T,Prism<?,?,A,B>>,ProtoOptic<Cocartesian<?,?,?>,S,T,A,B>
- All Known Subinterfaces:
Prism.Simple<S,A>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface Prism<S,T,A,B> extends ProtoOptic<Cocartesian<?,?,?>,S,T,A,B>, MonadRec<T,Prism<S,?,A,B>>, Profunctor<S,T,Prism<?,?,A,B>>
Prisms areIsosthat can fail in one direction. Example:Prism<String, String, Integer, Integer> parseInt = prism(str -> Either.trying(() -> Integer.parseInt(str), constantly(str)), Object::toString); String str = view(re(parseInt), 123); // "123" Maybe<Integer> works = view(pre(parseInt), "123"); // Just 123 Maybe<Integer> fails = view(pre(parseInt), "foo"); // NothingNote that because a
Prismmight fail in one direction, it cannot be immediately used forviewing; however, the combinatorsre,pre, andmatchingcan all be used to provide the additional context to aPrismso it can be used for viewing.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfacePrism.Simple<S,A>A convenience type with a simplified type signature for commonprismwith unifiedS/TandA/Btypes.
-
Method Summary
All Methods Static Methods Instance Methods Default Methods Modifier and Type Method Description default <Z,C>
Prism<S,T,Z,C>andThen(ProtoOptic<? super Cocartesian<?,?,?>,A,B,Z,C> f)Left-to-right composition of proto-optics.default <CoP extends Profunctor<?,?,? extends Cocartesian<?,?,?>>,CoF extends Functor<?,? extends Identity<?>>,FB extends Functor<B,? extends CoF>,FT extends Functor<T,? extends CoF>,PAFB extends Profunctor<A,FB,? extends CoP>,PSFT extends Profunctor<S,FT,? extends CoP>>
PSFTapply(PAFB pafb)The polymorphic arrow between profunctors in this optic interface.default <R,U>
Prism<R,U,A,B>compose(ProtoOptic<? super Cocartesian<?,?,?>,R,U,S,T> g)Right-to-Left composition of proto-optics.default <R> Prism<R,T,A,B>contraMap(Fn1<? super R,? extends S> fn)Contravariantly mapA <- B.default <R,U>
Prism<R,U,A,B>diMap(Fn1<? super R,? extends S> lFn, Fn1<? super T,? extends U> rFn)Dually map contravariantly over the left parameter and covariantly over the right parameter.default <R> Prism<R,T,A,B>diMapL(Fn1<? super R,? extends S> fn)Contravariantly map over the left parameter.default <U> Prism<S,U,A,B>diMapR(Fn1<? super T,? extends U> fn)Covariantly map over the right parameter.default <U> Prism<S,U,A,B>discardL(Applicative<U,Prism<S,?,A,B>> appB)Sequence both thisApplicativeandappB, discarding thisApplicative'sresult and returningappB.default <U> Prism<S,T,A,B>discardR(Applicative<U,Prism<S,?,A,B>> appB)Sequence both thisApplicativeandappB, discardingappB'sresult and returning thisApplicative.default <U> Prism<S,U,A,B>flatMap(Fn1<? super T,? extends Monad<U,Prism<S,?,A,B>>> f)Chain dependent computations that may continue or short-circuit based on previous results.default <U> Prism<S,U,A,B>fmap(Fn1<? super T,? extends U> fn)Covariantly transmute this functor's parameter using the given mapping function.static <S,A,B>
Prism<S,S,A,B>fromPartial(Fn1<? super S,? extends A> partialSa, Fn1<? super B,? extends S> bs)Static factory method for creating aPrismfrom a partial functionS -> Aand a total functionB -> S.default <U> Lazy<Prism<S,U,A,B>>lazyZip(Lazy<? extends Applicative<Fn1<? super T,? extends U>,Prism<S,?,A,B>>> lazyAppFn)Given alazyinstance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.default <C> Prism<S,T,C,B>mapA(Fn1<? super A,? extends C> fn)Covariantly mapAtoC, yielding a new optic.default <Z> Prism<S,T,A,Z>mapB(Fn1<? super Z,? extends B> fn)Contravariantly mapBtoZ, yielding a new optic.default <R> Prism<R,T,A,B>mapS(Fn1<? super R,? extends S> fn)Contravariantly mapStoR, yielding a new optic.default <U> Prism<S,U,A,B>mapT(Fn1<? super T,? extends U> fn)Covariantly mapTtoU, yielding a new optic.static <S,T,A,B>
Prism<S,T,A,B>prism(Fn1<? super S,? extends CoProduct2<T,A,?>> sta, Fn1<? super B,? extends T> bt)static <S,T,A,B>
Prism<S,T,A,B>prism(Optic<? super Cocartesian<?,?,?>,? super Functor<?,?>,S,T,A,B> optic)static <S,T,A,B>
Prism<S,T,A,B>prism(ProtoOptic<? super Cocartesian<?,?,?>,S,T,A,B> protoOptic)Promote aProtoOpticwith compatible bounds to anPrism.default <U> Prism<S,U,A,B>pure(U u)Lift the valuebinto this applicative functor.static <S,A,B>
Pure<Prism<S,?,A,B>>purePrism()static <S,A>
Prism.Simple<S,A>simplePrism(Fn1<? super S,? extends Maybe<A>> sMaybeA, Fn1<? super A,? extends S> as)Static factory method for creating a simplePrismfrom a function and its potentially failing inverse.default <U> Prism<S,U,A,B>trampolineM(Fn1<? super T,? extends MonadRec<RecursiveResult<T,U>,Prism<S,?,A,B>>> fn)Given some operation yielding aRecursiveResultinside thisMonadRec, internally trampoline the operation until it yields aterminationinstruction.default Tuple2<Fn1<? super B,? extends T>,Fn1<? super S,? extends Either<T,A>>>unPrism()default <U> Prism<S,U,A,B>zip(Applicative<Fn1<? super T,? extends U>,Prism<S,?,A,B>> appFn)Given another instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.-
Methods inherited from interface com.jnape.palatable.lambda.optics.Optic
andThen, compose, monomorphize
-
Methods inherited from interface com.jnape.palatable.lambda.optics.ProtoOptic
toOptic
-
-
-
-
Method Detail
-
unPrism
default Tuple2<Fn1<? super B,? extends T>,Fn1<? super S,? extends Either<T,A>>> unPrism()
-
apply
default <CoP extends Profunctor<?,?,? extends Cocartesian<?,?,?>>,CoF extends Functor<?,? extends Identity<?>>,FB extends Functor<B,? extends CoF>,FT extends Functor<T,? extends CoF>,PAFB extends Profunctor<A,FB,? extends CoP>,PSFT extends Profunctor<S,FT,? extends CoP>> PSFT apply(PAFB pafb)
The polymorphic arrow between profunctors in this optic interface.- Specified by:
applyin interfaceOptic<Cocartesian<?,?,?>,Identity<?>,S,T,A,B>- Specified by:
applyin interfaceProtoOptic<Cocartesian<?,?,?>,S,T,A,B>- Type Parameters:
CoP- the profunctor type constraint witnessed by the application of this opticCoF- the functor type constraint witnessed by the application of this opticFB- the covariant parameter type of the input profunctorFT- the covariant parameter type of the output profunctorPAFB- the full input typePSFT- the full output type- Parameters:
pafb- the input- Returns:
- the output profunctor
-
andThen
default <Z,C> Prism<S,T,Z,C> andThen(ProtoOptic<? super Cocartesian<?,?,?>,A,B,Z,C> f)
Left-to-right composition of proto-optics. Requires compatibility betweenSandT.- Specified by:
andThenin interfaceProtoOptic<Cocartesian<?,?,?>,S,T,A,B>- Type Parameters:
Z- the new left side of the input profunctorC- the new right side's functor embedding of the input profunctor- Parameters:
f- the other proto-optic- Returns:
- the composed proto-optic
-
compose
default <R,U> Prism<R,U,A,B> compose(ProtoOptic<? super Cocartesian<?,?,?>,R,U,S,T> g)
Right-to-Left composition of proto-optics. Requires compatibility betweenAandB.- Specified by:
composein interfaceProtoOptic<Cocartesian<?,?,?>,S,T,A,B>- Type Parameters:
R- the new left side of the output profunctorU- the new right side's functor embedding of the output profunctor- Parameters:
g- the other proto-optic- Returns:
- the composed proto-optic
-
mapS
default <R> Prism<R,T,A,B> mapS(Fn1<? super R,? extends S> fn)
Contravariantly mapStoR, yielding a new optic.- Specified by:
mapSin interfaceOptic<Cocartesian<?,?,?>,Identity<?>,S,T,A,B>- Specified by:
mapSin interfaceProtoOptic<Cocartesian<?,?,?>,S,T,A,B>- Type Parameters:
R- the new left side of the output profunctor- Parameters:
fn- the mapping function- Returns:
- the new optic
-
mapT
default <U> Prism<S,U,A,B> mapT(Fn1<? super T,? extends U> fn)
Covariantly mapTtoU, yielding a new optic.- Specified by:
mapTin interfaceOptic<Cocartesian<?,?,?>,Identity<?>,S,T,A,B>- Specified by:
mapTin interfaceProtoOptic<Cocartesian<?,?,?>,S,T,A,B>- Type Parameters:
U- the new right side's functor embedding of the output profunctor- Parameters:
fn- the mapping function- Returns:
- the new optic
-
mapA
default <C> Prism<S,T,C,B> mapA(Fn1<? super A,? extends C> fn)
Covariantly mapAtoC, yielding a new optic.- Specified by:
mapAin interfaceOptic<Cocartesian<?,?,?>,Identity<?>,S,T,A,B>- Specified by:
mapAin interfaceProtoOptic<Cocartesian<?,?,?>,S,T,A,B>- Type Parameters:
C- the new left side of the input profunctor- Parameters:
fn- the mapping function- Returns:
- the new optic
-
mapB
default <Z> Prism<S,T,A,Z> mapB(Fn1<? super Z,? extends B> fn)
Contravariantly mapBtoZ, yielding a new optic.- Specified by:
mapBin interfaceOptic<Cocartesian<?,?,?>,Identity<?>,S,T,A,B>- Specified by:
mapBin interfaceProtoOptic<Cocartesian<?,?,?>,S,T,A,B>- Type Parameters:
Z- the new right side's functor embedding of the input profunctor- Parameters:
fn- the mapping function- Returns:
- the new optic
-
flatMap
default <U> Prism<S,U,A,B> flatMap(Fn1<? super T,? extends Monad<U,Prism<S,?,A,B>>> f)
Chain dependent computations that may continue or short-circuit based on previous results.
-
fmap
default <U> Prism<S,U,A,B> fmap(Fn1<? super T,? extends U> fn)
Covariantly transmute this functor's parameter using the given mapping function. Generally this method is specialized to return an instance of the class implementing Functor.- Specified by:
fmapin interfaceApplicative<S,T>- Specified by:
fmapin interfaceFunctor<S,T>- Specified by:
fmapin interfaceMonad<S,T>- Specified by:
fmapin interfaceMonadRec<S,T>- Type Parameters:
U- the new parameter type- Parameters:
fn- the mapping function- Returns:
- a functor over B (the new parameter type)
-
zip
default <U> Prism<S,U,A,B> zip(Applicative<Fn1<? super T,? extends U>,Prism<S,?,A,B>> appFn)
Given another instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.
-
lazyZip
default <U> Lazy<Prism<S,U,A,B>> lazyZip(Lazy<? extends Applicative<Fn1<? super T,? extends U>,Prism<S,?,A,B>>> lazyAppFn)
Given alazyinstance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports. This is useful for applicatives that support lazy evaluation and early termination.- Specified by:
lazyZipin interfaceApplicative<S,T>- Specified by:
lazyZipin interfaceMonad<S,T>- Specified by:
lazyZipin interfaceMonadRec<S,T>- Type Parameters:
U- the resulting applicative parameter type- Parameters:
lazyAppFn- the lazy other applicative instance- Returns:
- the mapped applicative
- See Also:
Maybe,Either
-
discardL
default <U> Prism<S,U,A,B> discardL(Applicative<U,Prism<S,?,A,B>> appB)
Sequence both thisApplicativeandappB, discarding thisApplicative'sresult and returningappB. This is generally useful for sequentially performing side-effects.
-
discardR
default <U> Prism<S,T,A,B> discardR(Applicative<U,Prism<S,?,A,B>> appB)
Sequence both thisApplicativeandappB, discardingappB'sresult and returning thisApplicative. This is generally useful for sequentially performing side-effects.
-
trampolineM
default <U> Prism<S,U,A,B> trampolineM(Fn1<? super T,? extends MonadRec<RecursiveResult<T,U>,Prism<S,?,A,B>>> fn)
Given some operation yielding aRecursiveResultinside thisMonadRec, internally trampoline the operation until it yields aterminationinstruction.Stack-safety depends on implementations guaranteeing that the growth of the call stack is a constant factor independent of the number of invocations of the operation. For various examples of how this can be achieved in stereotypical circumstances, see the referenced types.
- Specified by:
trampolineMin interfaceMonadRec<S,T>- Type Parameters:
U- the ultimate resulting carrier type- Parameters:
fn- the function to internally trampoline- Returns:
- the trampolined
MonadRec - See Also:
for a basic implementation,for a implementation,for an implementation leveraging an already stack-safe,for a implementation
-
diMap
default <R,U> Prism<R,U,A,B> diMap(Fn1<? super R,? extends S> lFn, Fn1<? super T,? extends U> rFn)
Dually map contravariantly over the left parameter and covariantly over the right parameter. This is isomorphic todiMapL(lFn).diMapR(rFn).- Specified by:
diMapin interfaceProfunctor<S,T,A>- Type Parameters:
R- the new left parameter typeU- the new right parameter type- Parameters:
lFn- the left parameter mapping functionrFn- the right parameter mapping function- Returns:
- a profunctor over Z (the new left parameter type) and C (the new right parameter type)
-
diMapL
default <R> Prism<R,T,A,B> diMapL(Fn1<? super R,? extends S> fn)
Contravariantly map over the left parameter.- Specified by:
diMapLin interfaceProfunctor<S,T,A>- Type Parameters:
R- the new left parameter type- Parameters:
fn- the mapping function- Returns:
- a profunctor over Z (the new left parameter type) and C (the same right parameter type)
-
diMapR
default <U> Prism<S,U,A,B> diMapR(Fn1<? super T,? extends U> fn)
Covariantly map over the right parameter. For all profunctors that are also functors, it should hold thatdiMapR(f) == fmap(f).- Specified by:
diMapRin interfaceProfunctor<S,T,A>- Type Parameters:
U- the new right parameter type- Parameters:
fn- the mapping function- Returns:
- a profunctor over A (the same left parameter type) and C (the new right parameter type)
-
contraMap
default <R> Prism<R,T,A,B> contraMap(Fn1<? super R,? extends S> fn)
Contravariantly mapA <- B.- Specified by:
contraMapin interfaceContravariant<S,T>- Specified by:
contraMapin interfaceProfunctor<S,T,A>- Type Parameters:
R- the new parameter type- Parameters:
fn- the mapping function- Returns:
- the mapped Contravariant functor instance
-
prism
static <S,T,A,B> Prism<S,T,A,B> prism(Fn1<? super S,? extends CoProduct2<T,A,?>> sta, Fn1<? super B,? extends T> bt)
-
prism
static <S,T,A,B> Prism<S,T,A,B> prism(ProtoOptic<? super Cocartesian<?,?,?>,S,T,A,B> protoOptic)
Promote aProtoOpticwith compatible bounds to anPrism.- Type Parameters:
S- the input that might fail to map to its outputT- the guaranteed outputA- the output that might fail to be producedB- the input that guarantees its output- Parameters:
protoOptic- theProtoOptic- Returns:
- the
Prism
-
prism
static <S,T,A,B> Prism<S,T,A,B> prism(Optic<? super Cocartesian<?,?,?>,? super Functor<?,?>,S,T,A,B> optic)
-
simplePrism
static <S,A> Prism.Simple<S,A> simplePrism(Fn1<? super S,? extends Maybe<A>> sMaybeA, Fn1<? super A,? extends S> as)
Static factory method for creating a simplePrismfrom a function and its potentially failing inverse.- Type Parameters:
S- the input that might fail to map to its output and the guaranteed output from the other directionA- the output that might fail to be produced and the input that guarantees its output in the other direction- Parameters:
sMaybeA- a partial mapping fromS -> Aas- a total mapping fromA -> S- Returns:
- the
simple prism
-
fromPartial
static <S,A,B> Prism<S,S,A,B> fromPartial(Fn1<? super S,? extends A> partialSa, Fn1<? super B,? extends S> bs)
Static factory method for creating aPrismfrom a partial functionS -> Aand a total functionB -> S.- Type Parameters:
S- the input that might fail to map to its output and the guaranteed output from the other directionA- the output that might fail to be producedB- the input that guarantees its output in the other direction- Parameters:
partialSa- the partial directionbs- the reverse total direction- Returns:
- the
Prism
-
-