arrow-optics / arrow.optics / PPrism
interface PPrism<S, T, A, B> :
PPrismOf
<S, T, A, B>
A Prism is a loss less invertible optic that can look into a structure and optionally find its focus. Mostly used for finding a focus that is only present under certain conditions i.e. list head Prism<List, Int>
A (polymorphic) PPrism is useful when setting or modifying a value for a polymorphic sum type i.e. PPrism<Option, Option, String, Int>
A PPrism gathers the two concepts of pattern matching and constructor and thus can be seen as a pair of functions:
getOrModify: A -> Either<A, B>
meaning it returns the focus of a PPrism OR the original valuereverseGet : B -> A
meaning we can construct the source type of a PPrism from a focus B
S
- the source of a PPrism
T
- the modified source of a PPrism
A
- the focus of a PPrism
B
- the modified focus of a PPrism
all | Check if there is no focus or the focus satisfies the predicateopen fun all(s: S, p: (A) -> Boolean ): Boolean |
asFold | View a PPrism as a Foldopen fun asFold(): Fold <S, A> |
asOptional | View a PPrism as an POptionalopen fun asOptional(): POptional <S, T, A, B> |
asSetter | View a PPrism as a PSetteropen fun asSetter(): PSetter <S, T, A, B> |
asTraversal | View a PPrism as a PTraversalopen fun asTraversal(): PTraversal <S, T, A, B> |
compose | Compose a PPrism with another PPrismopen infix fun <C, D> compose(other: PPrism <A, B, C, D>): PPrism <S, T, C, D> Compose an Iso as an PPrism open infix fun <C, D> compose(other: PIso <A, B, C, D>): PPrism <S, T, C, D> Compose a PPrism with a POptional open infix fun <C, D> compose(other: POptional <A, B, C, D>): POptional <S, T, C, D> Compose a PPrism with a PLens open infix fun <C, D> compose(other: PLens <A, B, C, D>): POptional <S, T, C, D> Compose a PPrism with a PSetter open infix fun <C, D> compose(other: PSetter <A, B, C, D>): PSetter <S, T, C, D> Compose a PPrism with a Fold open infix fun <C> compose(other: Fold <A, C>): Fold <S, C> Compose a PPrism with a PTraversal open infix fun <C, D> compose(other: PTraversal <A, B, C, D>): PTraversal <S, T, C, D> |
exist | Check if there is a focus and it satisfies the predicateopen fun exist(s: S, p: (A) -> Boolean ): Boolean |
find | Find the focus that satisfies the predicateopen fun find(s: S, p: (A) -> Boolean ): Option<A> |
first | Create a product of the PPrism and a type Copen fun <C> first(): PPrism <Tuple2<S, C>, Tuple2<T, C>, Tuple2<A, C>, Tuple2<B, C>> |
getOption | Get the focus or Option.None if focus cannot be seenopen fun getOption(s: S): Option<A> |
getOrModify | abstract fun getOrModify(s: S): Either<T, A> |
isEmpty | Check if no focus can be seen by the PPrismopen fun isEmpty(s: S): Boolean |
left | Create a sum of the PPrism and a type Copen fun <C> left(): PPrism <Either<S, C>, Either<T, C>, Either<A, C>, Either<B, C>> |
lift | Lift a function f: (A) -> B to the context of S: (S) -> T``open fun lift(f: (A) -> B): (S) -> T` |
liftF | Modify the focus of a PPrism with an Applicative functionopen fun <F> liftF(FA: Applicative<F>, f: (A) -> Kind<F, B>): (S) -> Kind<F, T> |
liftOption | Lift a function f: (A) -> B to the context of S: (S) -> Option``open fun liftOption(f: (A) -> B): (S) -> Option |
modify | Modify the focus of a PPrism with a functionopen fun modify(s: S, f: (A) -> B): T |
modifyF | Modify the focus of a PPrism with an Applicative functionopen fun <F> modifyF(FA: Applicative<F>, s: S, f: (A) -> Kind<F, B>): Kind<F, T> |
modifyOption | Modify the focus of a PPrism with a functionopen fun modifyOption(s: S, f: (A) -> B): Option<T> |
nonEmpty | Check if a focus can be seen by the PPrismopen fun nonEmpty(s: S): Boolean |
plus | Plus operator overload to compose lensesopen operator fun <C, D> plus(other: PPrism <A, B, C, D>): PPrism <S, T, C, D> open operator fun <C, D> plus(other: POptional <A, B, C, D>): POptional <S, T, C, D> open operator fun <C, D> plus(other: PLens <A, B, C, D>): POptional <S, T, C, D> open operator fun <C, D> plus(other: PIso <A, B, C, D>): PPrism <S, T, C, D> open operator fun <C, D> plus(other: PSetter <A, B, C, D>): PSetter <S, T, C, D> open operator fun <C> plus(other: Fold <A, C>): Fold <S, C> open operator fun <C, D> plus(other: PTraversal <A, B, C, D>): PTraversal <S, T, C, D> |
reverseGet | abstract fun reverseGet(b: B): T |
right | Create a sum of a type C and the PPrismopen fun <C> right(): PPrism <Either<C, S>, Either<C, T>, Either<C, A>, Either<C, B>> |
second | Create a product of a type C and the PPrismopen fun <C> second(): PPrism <Tuple2<C, S>, Tuple2<C, T>, Tuple2<C, A>, Tuple2<C, B>> |
set | Set the focus of a PPrism with a valueopen fun set(s: S, b: B): T |
setOption | Set the focus of a PPrism with a valueopen fun setOption(s: S, b: B): Option<T> |
id | fun <S> id(): PPrism <S, S, S, S> |
invoke | Invoke operator overload to create a PPrism of type S with focus A . Can also be used to construct Prismoperator fun <S, T, A, B> invoke(getOrModify: (S) -> Either<T, A>, reverseGet: (B) -> T): PPrism <S, T, A, B> |
none | Prism to focus into an arrow.core.Nonefun <A> none(): Prism <Option<A>, Unit > |
only | A PPrism that checks for equality with a given value afun <A> only(a: A, EQA: Eq<A>): Prism <A, Unit > |
pSome | PPrism to focus into an arrow.core.Somefun <A, B> pSome(): PPrism <Option<A>, Option<B>, A, B> |
some | Prism to focus into an arrow.core.Somefun <A> some(): Prism <Option<A>, A> |
some | DSL to compose a Prism with focus arrow.core.Some with a Prism with a focus of Option<S>val <T, S> Prism <T, Option<S>>.some: Prism <T, S> |
at | DSL to compose At with a Prism for a structure S to focus in on A at given index I.fun <T, S, I, A> Prism <T, S>.at(AT: At <S, I, A>, i: I): Optional <T, A> |
every | DSL to compose Each with a Prism for a structure S to see all its foci Afun <T, S, A> Prism <T, S>.~~every~~(EA: Each <S, A>): Traversal <T, A> DSL to compose Traversal with a Prism for a structure S to see all its foci A fun <T, S, A> Prism <T, S>.every(TR: Traversal <S, A>): Traversal <T, A> |
index | DSL to compose Index with a Prism for a structure S to focus in on A at given index Ifun <T, S, I, A> Prism <T, S>.index(ID: Index <S, I, A>, i: I): Optional <T, A> |
Do you like Arrow?
✖