arrow-optics / arrow.optics / POptional

POptional

@higherkind interface POptional<S, T, A, B> : POptionalOf<S, T, A, B>

An Optional is an optic that allows to see into a structure and getting, setting or modifying an optional focus.

A (polymorphic) POptional is useful when setting or modifying a value for a type with a optional polymorphic focus i.e. POptional<Ior<Int, Double>, Ior<String, Double>, Int, String>

A POptional can be seen as a weaker Lens and Prism and combines their weakest functions:

  • set: (S, B) -> T meaning we can focus into an S and set a value B for a target A and obtain a modified source T
  • getOrModify: (S) -> Either<T, A> meaning it returns the focus of a POptional OR the original value

Parameters

S - the source of a POptional

T - the modified source of a POptional

A - the focus of a POptional

B - the modified focus of a POptional

Functions

| all | open fun all(s: S, p: (A) -> Boolean): Boolean
Check if there is no focus or the target satisfies the predicate p | | asFold | open fun asFold(): Fold<S, A>
View a POptional as a Fold | | asSetter | open fun asSetter(): PSetter<S, T, A, B>
View a POptional as a PSetter | | asTraversal | open fun asTraversal(): PTraversal<S, T, A, B>
View a POptional as a PTraversal | | choice | open infix fun <S1, T1> choice(other: POptional<S1, T1, A, B>): POptional<Either<S, S1>, Either<T, T1>, A, B>
Join two POptional with the same focus B | | compose | open infix fun <C, D> compose(other: POptional<A, B, C, D>): POptional<S, T, C, D>
Compose a POptional with a POptionalopen infix fun <C, D> compose(other: PPrism<A, B, C, D>): POptional<S, T, C, D>
Compose a POptional with a PPrismopen infix fun <C, D> compose(other: PLens<A, B, C, D>): POptional<S, T, C, D>
Compose a POptional with a PLensopen infix fun <C, D> compose(other: PIso<A, B, C, D>): POptional<S, T, C, D>
open infix fun <C, D> compose(other: PSetter<A, B, C, D>): PSetter<S, T, C, D>
Compose a POptional with a PIsoopen infix fun <C> compose(other: Fold<A, C>): Fold<S, C>
open infix fun <C> compose(other: Getter<A, C>): Fold<S, C>
Compose a POptional with a Foldopen infix fun <C, D> compose(other: PTraversal<A, B, C, D>): PTraversal<S, T, C, D>
Compose a POptional with a PTraversal | | exists | open fun exists(s: S, p: (A) -> Boolean): Boolean
Check if there is a focus and it satisfies the predicate p | | extract | open fun extract(): State<S, Option<A>>
Extracts the focus A viewed through the POptional. | | extractMap | open fun <C> extractMap(f: (A) -> C): State<S, Option<C>>
Extract and map the focus A viewed through the POptional and applies f to it. | | find | open fun find(s: S, p: (A) -> Boolean): Option<A>
Find the focus that satisfies the predicate p | | first | open fun <C> first(): POptional<Tuple2<S, C>, Tuple2<T, C>, Tuple2<A, C>, Tuple2<B, C>>
Create a product of the POptional and a type C | | getOption | open fun getOption(a: S): Option<A>
Get the focus of a POptional or Option.None if the is not there | | getOrModify | abstract fun getOrModify(s: S): Either<T, A>
Get the focus of a POptional or return the original value while allowing the type to change if it does not match | | isEmpty | open fun isEmpty(s: S): Boolean
Check if there is no focus | | lift | open fun lift(f: (A) -> B): (S) -> T
Lift a function f: (A) -> B to the context of S: (S) -> T | | [liftF](lift-f.html) | open fun liftF(FA: Applicative<`[`F`](lift-f.html#F)`>, f: (`[`A`](index.html#A)`) -> Kind<`[`F`](lift-f.html#F)`, `[`B`](index.html#B)`>): (`[`S`](index.html#S)`) -> Kind<`[`F`](lift-f.html#F)`, `[`T`](index.html#T)`>`
Lift a function [f](lift-f.html#arrow.optics.POptional$liftF(arrow.typeclasses.Applicative((arrow.optics.POptional.liftF.F)), kotlin.Function1((arrow.optics.POptional.A, arrow.Kind((arrow.optics.POptional.liftF.F, arrow.optics.POptional.B)))))/f): `(A) -> Kind<F, B> to the context of `S`: `(S) -> Kind<F, T>` | | [modifiyOption](modifiy-option.html) | `open fun modifiyOption(s: `[`S`](index.html#S)`, f: (`[`A`](index.html#A)`) -> `[`B`](index.html#B)`): Option<`[`T`](index.html#T)`>`
Modify the focus of a [POptional](./index.html) with a function [f](modifiy-option.html#arrow.optics.POptional$modifiyOption(arrow.optics.POptional.S, kotlin.Function1((arrow.optics.POptional.A, arrow.optics.POptional.B)))/f) | | [modify](modify.html) | `open fun modify(s: `[`S`](index.html#S)`, f: (`[`A`](index.html#A)`) -> `[`B`](index.html#B)`): `[`T`](index.html#T)
Modify the focus of a [POptional](./index.html) with a function [f](modify.html#arrow.optics.POptional$modify(arrow.optics.POptional.S, kotlin.Function1((arrow.optics.POptional.A, arrow.optics.POptional.B)))/f) | | [modifyF](modify-f.html) | `open fun modifyF(FA: Applicative<`[`F`](modify-f.html#F)`>, s: `[`S`](index.html#S)`, f: (`[`A`](index.html#A)`) -> Kind<`[`F`](modify-f.html#F)`, `[`B`](index.html#B)`>): Kind<`[`F`](modify-f.html#F)`, `[`T`](index.html#T)`>`
Modify the focus of a [POptional](./index.html) with an Applicative function [f](modify-f.html#arrow.optics.POptional$modifyF(arrow.typeclasses.Applicative((arrow.optics.POptional.modifyF.F)), arrow.optics.POptional.S, kotlin.Function1((arrow.optics.POptional.A, arrow.Kind((arrow.optics.POptional.modifyF.F, arrow.optics.POptional.B)))))/f) | | [nonEmpty](non-empty.html) | `open fun nonEmpty(s: `[`S`](index.html#S)`): `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)
Check if there is a focus | | [plus](plus.html) | `open operator fun <C, D> plus(o: `[`POptional`](./index.html)`<`[`A`](index.html#A)`, `[`B`](index.html#B)`, `[`C`](plus.html#C)`, `[`D`](plus.html#D)`>): `[`POptional`](./index.html)`<`[`S`](index.html#S)`, `[`T`](index.html#T)`, `[`C`](plus.html#C)`, `[`D`](plus.html#D)`>`
Plus operator overload to compose optionals`open operator fun <C, D> plus(o: `[`PPrism`](../-p-prism/index.html)`<`[`A`](index.html#A)`, `[`B`](index.html#B)`, `[`C`](plus.html#C)`, `[`D`](plus.html#D)`>): `[`POptional`](./index.html)`<`[`S`](index.html#S)`, `[`T`](index.html#T)`, `[`C`](plus.html#C)`, `[`D`](plus.html#D)`>`
`open operator fun <C, D> plus(o: `[`PLens`](../-p-lens/index.html)`<`[`A`](index.html#A)`, `[`B`](index.html#B)`, `[`C`](plus.html#C)`, `[`D`](plus.html#D)`>): `[`POptional`](./index.html)`<`[`S`](index.html#S)`, `[`T`](index.html#T)`, `[`C`](plus.html#C)`, `[`D`](plus.html#D)`>`
`open operator fun <C, D> plus(o: `[`PIso`](../-p-iso/index.html)`<`[`A`](index.html#A)`, `[`B`](index.html#B)`, `[`C`](plus.html#C)`, `[`D`](plus.html#D)`>): `[`POptional`](./index.html)`<`[`S`](index.html#S)`, `[`T`](index.html#T)`, `[`C`](plus.html#C)`, `[`D`](plus.html#D)`>`
`open operator fun <C, D> plus(o: `[`PSetter`](../-p-setter/index.html)`<`[`A`](index.html#A)`, `[`B`](index.html#B)`, `[`C`](plus.html#C)`, `[`D`](plus.html#D)`>): `[`PSetter`](../-p-setter/index.html)`<`[`S`](index.html#S)`, `[`T`](index.html#T)`, `[`C`](plus.html#C)`, `[`D`](plus.html#D)`>`
`open operator fun plus(o: `[`Fold`](../-fold/index.html)`<`[`A`](index.html#A)`, `[`C`](plus.html#C)`>): `[`Fold`](../-fold/index.html)`<`[`S`](index.html#S)`, `[`C`](plus.html#C)`>`
`open operator fun plus(o: `[`Getter`](../-getter/index.html)`<`[`A`](index.html#A)`, `[`C`](plus.html#C)`>): `[`Fold`](../-fold/index.html)`<`[`S`](index.html#S)`, `[`C`](plus.html#C)`>`
`open operator fun <C, D> plus(o: `[`PTraversal`](../-p-traversal/index.html)`<`[`A`](index.html#A)`, `[`B`](index.html#B)`, `[`C`](plus.html#C)`, `[`D`](plus.html#D)`>): `[`PTraversal`](../-p-traversal/index.html)`<`[`S`](index.html#S)`, `[`T`](index.html#T)`, `[`C`](plus.html#C)`, `[`D`](plus.html#D)`>` | | [second](second.html) | `open fun second(): `[`POptional`](./index.html)`<Tuple2<`[`C`](second.html#C)`, `[`S`](index.html#S)`>, Tuple2<`[`C`](second.html#C)`, `[`T`](index.html#T)`>, Tuple2<`[`C`](second.html#C)`, `[`A`](index.html#A)`>, Tuple2<`[`C`](second.html#C)`, `[`B`](index.html#B)`>>`
Create a product of a type [C](second.html#C) and the [POptional](./index.html) | | [set](set.html) | `abstract fun set(s: `[`S`](index.html#S)`, b: `[`B`](index.html#B)`): `[`T`](index.html#T)
Get the modified source of a [POptional](./index.html) | | [setOption](set-option.html) | `open fun setOption(s: `[`S`](index.html#S)`, b: `[`B`](index.html#B)`): Option<`[`T`](index.html#T)`>`
Set the focus of a [POptional](./index.html) with a value. | | [toState](to-state.html) | `open fun toState(): State<`[`S`](index.html#S)`, Option<`[`A`](index.html#A)`>>`
Transforms a [POptional](./index.html) into a [State](#). Alias for [extract](extract.html). |

Companion Object Functions

codiagonal fun <S> codiagonal(): Optional<Either<S, S>, S>
POptional that takes either S or S and strips the choice of S.
id fun <S> id(): POptional<S, S, S, S>
invoke operator fun <S, T, A, B> invoke(getOrModify: (S) -> Either<T, A>, set: (S, B) -> T): POptional<S, T, A, B>
operator fun <S, A> invoke(partialFunction: PartialFunction<S, A>, set: (S, A) -> S): Optional<S, A>
Invoke operator overload to create a POptional of type S with focus A. Can also be used to construct Optional
void fun <A, B> void(): Optional<A, B>
POptional that never sees its focus

Extension Properties

every open val <T> Optional<T, S>.every: Traversal<T, A>
DSL to compose Each with a Optional for a structure S to see all its foci A
some val <T, S> Optional<T, Option<S>>.some: Optional<T, S>
DSL to compose a Prism with focus arrow.core.Some with a Optional with a focus of Option<S>

Extension Functions

assign fun <S, A> Optional<S, A>.assign(a: A): State<S, Option<A>>
Assign the focus A viewed through the Optional and returns its new value.
assignOld fun <S, A> Optional<S, A>.assignOld(a: A): State<S, Option<A>>
Assign the value focus A through the Optional and returns its old value.
assign_ fun <S, A> Optional<S, A>.assign_(a: A): State<S, Unit>
Assign the focus A viewed through the Optional and ignores both values.
at fun <T, S, I, A> Optional<T, S>.at(AT: At<S, I, A>, i: I): Optional<T, A>
DSL to compose At with an Optional for a structure S to focus in on A at given index I.
every fun <T, S, A> Optional<T, S>.every(EA: Each<S, A>): Traversal<T, A>
DSL to compose Each with an Optional for a structure S to see all its foci A
index fun <T, S, I, A> Optional<T, S>.index(ID: Index<S, I, A>, i: I): Optional<T, A>
DSL to compose Index with an Optional for a structure S to focus in on A at given index I
update fun <S, A> Optional<S, A>.update(f: (A) -> A): State<S, Option<A>>
Update the focus A viewed through the Optional and returns its new value.
updateOld fun <S, A> Optional<S, A>.updateOld(f: (A) -> A): State<S, Option<A>>
Update the focus A viewed through the Optional and returns its old value.
update_ fun <S, A> Optional<S, A>.update_(f: (A) -> A): State<S, Unit>
Update the focus A viewed through the Optional and ignores both values.