PLens

interface PLens<S, T, A, B> : Getter<S, A> , POptional<S, T, A, B> , PSetter<S, T, A, B> , PTraversal<S, T, A, B> , PEvery<S, T, A, B> (source)

A Lens (or Functional Reference) is an optic that can focus into a structure for getting, setting or modifying the focus (target).

A (polymorphic) PLens is useful when setting or modifying a value for a constructed type i.e. PLens, Pair, Double, String>

A PLens can be seen as a pair of functions:

  • get: (S) -> A meaning we can focus into an S and extract an A

  • set: (B) -> (S) -> T meaning we can focus into an S and set a value B for a target A and obtain a modified source T

Parameters

S

the source of a PLens

T

the modified source of a PLens

A

the focus of a PLens

B

the modified focus of a PLens

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open fun all(source: S, predicate: (focus: A) -> Boolean): Boolean

Check if all targets satisfy the predicate

Link copied to clipboard
open fun any(source: S, predicate: (focus: A) -> Boolean): Boolean

Returns true if at least one focus matches the given predicate.

Link copied to clipboard
open infix fun <C> choice(other: Fold<C, A>): Fold<Either<S, C>, A>

Join two Fold with the same target

open infix fun <C> choice(other: Getter<C, A>): Getter<Either<S, C>, A>

Join two Getter with the same focus

open infix fun <S1, T1> choice(other: PLens<S1, T1, A, B>): PLens<Either<S, S1>, Either<T, T1>, A, B>

Join two PLens with the same focus in A

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

open infix fun <S1, T1> choice(other: POptionalGetter<S1, T1, A>): POptionalGetter<Either<S, S1>, Either<T, T1>, A>

Join two POptionalGetter with the same focus

open infix fun <U, V> choice(other: PSetter<U, V, A, B>): PSetter<Either<S, U>, Either<T, V>, A, B>

Join two PSetter with the same target

open fun <U, V> choice(other: PTraversal<U, V, A, B>): PTraversal<Either<S, U>, Either<T, V>, A, B>
Link copied to clipboard
open infix fun <C> compose(other: Fold<in A, out C>): Fold<S, C>

Compose a Fold with a Fold

open infix fun <C> compose(other: Getter<in A, out C>): Getter<S, C>

Compose a Getter with a Getter

open infix fun <C, D> compose(other: PEvery<in A, out B, out C, in D>): PEvery<S, T, C, D>

Compose a PEvery with a PEvery

open infix fun <C, D> compose(other: PLens<in A, out B, out C, in D>): PLens<S, T, C, D>

Compose a PLens with another PLens

open infix fun <C, D> compose(other: POptional<in A, out B, out C, in D>): POptional<S, T, C, D>

Compose a POptional with a POptional

open infix fun <C> compose(other: POptionalGetter<in A, T, out C>): POptionalGetter<S, T, C>
open infix fun <C, D> compose(other: PSetter<in A, out B, out C, in D>): PSetter<S, T, C, D>

Compose a PSetter with a PSetter

open infix fun <C, D> compose(other: PTraversal<in A, out B, out C, in D>): PTraversal<S, T, C, D>

Compose a PTraversal with a PTraversal

Link copied to clipboard
open fun exists(source: S, predicate: (focus: A) -> Boolean): Boolean

Check whether at least one element satisfies the predicate.

Link copied to clipboard
open fun findOrNull(source: S, predicate: (focus: A) -> Boolean): A?

Find the first element matching the predicate, if one exists.

Link copied to clipboard
open override fun <C> first(): PLens<Pair<S, C>, Pair<T, C>, Pair<A, C>, Pair<B, C>>

Create a product of the PLens and a type C

Link copied to clipboard
open fun firstOrNull(source: S): A?

Get the first target or null

Link copied to clipboard
open fun fold(M: Monoid<A>, source: S): A

Fold using the given Monoid instance.

Link copied to clipboard
open override fun <R> foldMap(M: Monoid<R>, source: S, map: (focus: A) -> R): R

Map each target to a type R and use a Monoid to fold the results

Link copied to clipboard
abstract override fun get(source: S): A

Get the focus of a Getter

Link copied to clipboard
open fun getAll(source: S): List<A>

Get all targets of the Fold

Link copied to clipboard
open override fun getOrModify(source: 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

Link copied to clipboard
open fun getOrNull(source: S): A?

Get the focus of an OptionalGetter or null if the is not there

Link copied to clipboard
open fun isEmpty(source: S): Boolean

Check if there is no target

Link copied to clipboard
open fun isNotEmpty(source: S): Boolean

Check if there is at least one target

Link copied to clipboard
open fun lastOrNull(source: S): A?

Get the last target or null

Link copied to clipboard
open override fun <C> left(): Getter<Either<S, C>, Either<A, C>>

Create a sum of the Getter and type C

Link copied to clipboard
open fun lift(map: (focus: A) -> B): (source: S) -> T

Lift a function map: (A) -> B to the context of S: (S) -> T`

Link copied to clipboard
open override fun modify(source: S, map: (focus: A) -> B): T

Modify the focus of a POptional with a function map

Link copied to clipboard
open fun modifyNullable(source: S, map: (focus: A) -> B): T?

Modify the focus of a POptional with a function map

Link copied to clipboard
open operator fun <C> plus(other: Fold<in A, out C>): Fold<S, C>
open operator fun <C> plus(other: Getter<in A, out C>): Getter<S, C>
open operator fun <C, D> plus(other: PEvery<in A, out B, out C, in D>): PEvery<S, T, C, D>
open operator fun <C, D> plus(other: PLens<in A, out B, out C, in D>): PLens<S, T, C, D>
open operator fun <C, D> plus(other: POptional<in A, out B, out C, in D>): POptional<S, T, C, D>
open operator fun <C, D> plus(other: POptionalGetter<in A, T, out C>): POptionalGetter<S, T, C>
open operator fun <C, D> plus(other: PSetter<in A, out B, out C, in D>): PSetter<S, T, C, D>
open operator fun <C, D> plus(other: PTraversal<in A, out B, out C, in D>): PTraversal<S, T, C, D>
Link copied to clipboard
open override fun <C> right(): Getter<Either<C, S>, Either<C, A>>

Create a sum of type C and the Getter

Link copied to clipboard
open override fun <C> second(): PLens<Pair<C, S>, Pair<C, T>, Pair<C, A>, Pair<C, B>>

Create a product of a type C and the PLens

Link copied to clipboard
abstract override fun set(source: S, focus: B): T

Get the modified source of a POptional

Link copied to clipboard
open fun setNullable(source: S, b: B): T?

Set the focus of a POptional with a value.

Link copied to clipboard
open fun size(source: S): Int

Calculate the number of targets

Link copied to clipboard
open infix fun <C, D> split(other: Getter<C, D>): Getter<Pair<S, C>, Pair<A, D>>

Pair two disjoint Getter

open infix fun <S1, T1, A1, B1> split(other: PLens<S1, T1, A1, B1>): PLens<Pair<S, S1>, Pair<T, T1>, Pair<A, A1>, Pair<B, B1>>

Pair two disjoint PLens

Link copied to clipboard
open infix fun <C> zip(other: Getter<S, C>): Getter<S, Pair<A, C>>

Zip two Getter optics with the same source S

Properties

Link copied to clipboard
open val <U, V> PLens<U, V, S, T>.every: PTraversal<U, V, A, B>

DSL to compose Traversal with a Lens for a structure S to see all its foci A

open val <U, V> PIso<U, V, S, T>.every: PTraversal<U, V, A, B>

DSL to compose Traversal with a Iso for a structure S to see all its foci A

open val <U, V> PPrism<U, V, S, T>.every: PTraversal<U, V, A, B>

DSL to compose Traversal with a Prism for a structure S to see all its foci A

open val <U, V> POptional<U, V, S, T>.every: PTraversal<U, V, A, B>

DSL to compose Traversal with a Optional for a structure S to see all its foci A

open val <U, V> PSetter<U, V, S, T>.every: PSetter<U, V, A, B>

DSL to compose Traversal with a Setter for a structure S to see all its foci A

open val <U, V> PTraversal<U, V, S, T>.every: PTraversal<U, V, A, B>

DSL to compose Traversal with a Traversal for a structure S to see all its foci A

open val <U, V> PEvery<U, V, S, T>.every: PTraversal<U, V, A, B>

DSL to compose Traversal with a PEvery for a structure S to see all its foci A

Inheritors

Link copied to clipboard

Extensions

Link copied to clipboard
fun <T, S, I, A> Lens<T, S>.at(AT: At<S, I, A>, i: I): Lens<T, A>

DSL to compose At with a Lens for a structure S to focus in on A at given index I.

fun <T, S, I, A> Getter<T, S>.at(AT: At<S, I, A>, i: I): Getter<T, A>

DSL to compose At with a Getter for a structure S to focus in on A at given index I.

fun <T, S, I, A> Fold<T, S>.at(AT: At<S, I, A>, i: I): Fold<T, A>

DSL to compose At with a Fold for a structure S to focus in on A at given index I.

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.

fun <T, S, I, A> Setter<T, S>.at(AT: At<S, I, A>, i: I): Setter<T, A>

DSL to compose At with a Setter for a structure S to focus in on A at given index I.

fun <T, S, I, A> Traversal<T, S>.at(AT: At<S, I, A>, i: I): Traversal<T, A>

DSL to compose At with a Traversal for a structure S to focus in on A at given index I.

Link copied to clipboard
fun <T, S, A> Lens<T, S>.every(TR: Every<S, A>): Every<T, A>

DSL to compose Traversal with a Lens for a structure S to see all its foci A

fun <T, S, A> Fold<T, S>.every(TR: Every<S, A>): Fold<T, A>

DSL to compose Traversal with a Fold for a structure S to see all its foci A

fun <T, S, A> Optional<T, S>.every(TR: Every<S, A>): Every<T, A>

DSL to compose Traversal with an Optional for a structure S to see all its foci A

fun <T, S, A> Setter<T, S>.every(TR: Every<S, A>): Setter<T, A>

DSL to compose Traversal with a Setter for a structure S to see all its foci A

fun <T, S, A> Traversal<T, S>.every(TR: Every<S, A>): Traversal<T, A>

DSL to compose Traversal with a Traversal for a structure S to see all its foci A

Link copied to clipboard
operator fun <A, T> PLens<T, T, List<A>, List<A>>.get(i: Int): POptional<T, T, A, A>
Link copied to clipboard
fun <T, S, I, A> Lens<T, S>.index(ID: Index<S, I, A>, i: I): Optional<T, A>

DSL to compose Index with a Lens for a structure S to focus in on A at given index I

fun <T, S, I, A> Fold<T, S>.index(ID: Index<S, I, A>, i: I): Fold<T, A>

DSL to compose Index with a Fold for a structure S to focus in on A at given index I

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

fun <T, S, I, A> Setter<T, S>.index(ID: Index<S, I, A>, i: I): Setter<T, A>

DSL to compose Index with a Setter for a structure S to focus in on A at given index I

fun <T, S, I, A> Traversal<T, S>.index(ID: Index<S, I, A>, i: I): Traversal<T, A>

DSL to compose Index with a Traversal for a structure S to focus in on A at given index I

Link copied to clipboard
val <A, L, R> Optional<A, Either<L, R>>.left: Optional<A, L>

DSL to compose a Optional with focus Either with a Prism with a focus of Either.Left<L>

val <A, L, R> Traversal<A, Either<L, R>>.left: Traversal<A, L>

DSL to compose a Traversal with focus Either with a Prism with a focus of Either.Left<L>

Link copied to clipboard
val <A, L, R> Optional<A, Either<L, R>>.right: Optional<A, R>

DSL to compose a Optional with focus Either with a Prism with a focus of Either.Right<R>

val <A, L, R> Traversal<A, Either<L, R>>.right: Traversal<A, R>

DSL to compose a Traversal with focus Either with a Prism with a focus of Either.Right<R>

Link copied to clipboard
val <T, S> Lens<T, Option<S>>.some: Optional<T, S>

DSL to compose a Prism with focus arrow.core.Some with a Lens with a focus of Option<S>

val <T, S> Fold<T, Option<S>>.some: Fold<T, S>

DSL to compose a Prism with focus arrow.core.Some with a Fold with a focus of Option<S>

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>

val <T, S> Setter<T, Option<S>>.some: Setter<T, S>

DSL to compose a Prism with focus arrow.core.Some with a Setter with a focus of Option<S>

DSL to compose a Prism with focus arrow.core.Some with a Traversal with a focus of Option<S>