S - the source of a PPrismT - the modified source of a PPrismA - the target of a PPrismB - the modified target of a PPrismpublic abstract class PPrism<S,T,A,B> extends Object
PPrism can be seen as a pair of functions: - `getOrModify: S =>
T \/ A` - `reverseGet : B => T`
A PPrism could also be defined as a weaker PIso where get can
fail.
Typically a PPrism or Prism 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 type `A` to `B` and `S` to `T`. Prism is a PPrism
where the type of target cannot be modified.
A PPrism is also a valid Fold, POptional,
PTraversal and PSetter
| Modifier and Type | Method and Description |
|---|---|
Fold<S,A> |
asFold()
|
POptional<S,T,A,B> |
asOptional()
|
PSetter<S,T,A,B> |
asSetter()
|
PTraversal<S,T,A,B> |
asTraversal()
view a
PPrism as a PTraversal |
<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 a
PPrism with a PTraversal |
abstract Option<A> |
getOption(S s)
get the target of a
PPrism or nothing if there is no target |
abstract Either<T,A> |
getOrModify(S s)
get the target of a
PPrism or modify the source in case there is no
target |
boolean |
isMatching(S s)
check if a
PPrism has a target |
Function<S,T> |
modify(Function<A,B> f)
modify polymorphically the target of a
PPrism with a function |
<L> Function<S,Either<L,T>> |
modifyEitherF(Function<A,Either<L,B>> f)
modify polymorphically the target of a
PPrism with an Applicative
function |
<C> Function<S,Function<C,T>> |
modifyFunctionF(Function<A,Function<C,B>> f)
modify polymorphically the target of a
PPrism with an Applicative
function |
Function<S,Iterable<T>> |
modifyIterableF(Function<A,Iterable<B>> f)
modify polymorphically the target of a
PPrism with an Applicative
function |
Function<S,Option<T>> |
modifyOption(Function<A,B> f)
modify polymorphically the target of a
PPrism with a function. |
Function<S,Option<T>> |
modifyOptionF(Function<A,Option<B>> f)
modify polymorphically the target of a
PPrism with an Applicative
function |
Function<S,Pair<T,T>> |
modifyPairF(Function<A,Pair<B,B>> f)
modify polymorphically the target of a
PPrism with an Applicative
function |
Function<S,Supplier<T>> |
modifySupplierF(Function<A,Supplier<B>> f)
modify polymorphically the target of a
PPrism with an Applicative
function |
static <S,T> PPrism<S,T,S,T> |
pId() |
static <S,T,A,B> PPrism<S,T,A,B> |
pPrism(Function<S,Either<T,A>> getOrModify,
Function<B,T> reverseGet)
create a
PPrism using the canonical functions: getOrModify and
reverseGet |
Getter<B,T> |
re()
|
abstract T |
reverseGet(B b)
get the modified source of a
PPrism |
Function<S,T> |
set(B b)
set polymorphically the target of a
PPrism with a value |
Function<S,Option<T>> |
setOption(B b)
set polymorphically the target of a
PPrism with a value. |
public abstract Either<T,A> getOrModify(S s)
PPrism or modify the source in case there is no
targetpublic abstract Option<A> getOption(S s)
PPrism or nothing if there is no targetpublic final <C> Function<S,Function<C,T>> modifyFunctionF(Function<A,Function<C,B>> f)
PPrism with an Applicative
functionpublic final <L> Function<S,Either<L,T>> modifyEitherF(Function<A,Either<L,B>> f)
PPrism with an Applicative
functionpublic final Function<S,Option<T>> modifyOptionF(Function<A,Option<B>> f)
PPrism with an Applicative
functionpublic final Function<S,Pair<T,T>> modifyPairF(Function<A,Pair<B,B>> f)
PPrism with an Applicative
functionpublic final Function<S,Supplier<T>> modifySupplierF(Function<A,Supplier<B>> f)
PPrism with an Applicative
functionpublic final Function<S,Iterable<T>> modifyIterableF(Function<A,Iterable<B>> f)
PPrism with an Applicative
functionpublic final Function<S,T> modify(Function<A,B> f)
PPrism with a functionpublic final <C,D> PTraversal<S,T,C,D> composeTraversal(PTraversal<A,B,C,D> other)
PPrism with a PTraversalpublic PTraversal<S,T,A,B> asTraversal()
PPrism as a PTraversalpublic static <S,T> PPrism<S,T,S,T> pId()
Copyright © 2017 Atlassian. All rights reserved.