PIso

interface PIso<S, T, A, B> : PPrism<S, T, A, B> , PLens<S, T, A, B>

An Iso is a loss less invertible optic that defines an isomorphism between a type S and A i.e. a data class and its properties represented by TupleN

A (polymorphic) PIso is useful when setting or modifying a value for a constructed type i.e. PIso

An PIso is also a valid PLens, PPrism

Parameters

S

the source of a PIso

T

the modified source of a PIso

A

the focus of a PIso

B

the modified target of a PIso

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
@get:JvmName(name = "everyRight")
val <T, Error, A> Traversal<T, Either<Error, A>>.every: Traversal<T, A>
@get:JvmName(name = "everyNonEmptyList")
val <T, A> Traversal<T, NonEmptyList<A>>.every: Traversal<T, A>
@get:JvmName(name = "everySome")
val <T, A> Traversal<T, Option<A>>.every: Traversal<T, A>
@get:JvmName(name = "everyChar")
val <T> Traversal<T, String>.every: Traversal<T, Char>
val <T, A> Traversal<T, List<A>>.every: Traversal<T, A>
@get:JvmName(name = "everyValue")
val <T, K, V> Traversal<T, Map<K, V>>.every: Traversal<T, V>
@get:JvmName(name = "everySequence")
val <T, A> Traversal<T, Sequence<A>>.every: Traversal<T, A>
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> Prism<A, Either<L, R>>.left: Prism<A, L>

DSL to compose a Prism 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 <T, S> Optional<T, S?>.notNull: Optional<T, S>

DSL to compose an Optional with focus on a nullable type with notNull.

val <T, S> Traversal<T, S?>.notNull: Traversal<T, S>

DSL to compose a Traversal with focus on a nullable type with notNull.

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> Prism<A, Either<L, R>>.right: Prism<A, R>

DSL to compose a Prism 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> 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>

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

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
infix fun <T, A, B> PTraversal<T, T, A, B>.and(other: PTraversal<T, T, A, B>): PTraversal<T, T, A, B>

Traversal that aggregates the elements of two other traversals.

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
fun <T, K, V> Lens<T, Map<K, V>>.at(key: K): Lens<T, Option<V>>
@JvmName(name = "atSet")
fun <T, A> Lens<T, Set<A>>.at(value: A): Lens<T, Boolean>
fun <T, K, V> Optional<T, Map<K, V>>.at(key: K): Optional<T, Option<V>>
@JvmName(name = "atSet")
fun <T, A> Optional<T, Set<A>>.at(value: A): Optional<T, Boolean>
fun <T, K, V> Traversal<T, Map<K, V>>.at(key: K): Traversal<T, Option<V>>
@JvmName(name = "atSet")
fun <T, A> Traversal<T, Set<A>>.at(value: A): Traversal<T, Boolean>

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> 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> 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
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 fun <U, V> choice(other: PTraversal<U, V, A, B>): PTraversal<Either<S, U>, Either<T, V>, A, B>

Join two PTraversal with the same target

Link copied to clipboard
open infix fun <C, D> compose(other: PIso<in A, out B, out C, in D>): PIso<S, T, C, D>

Compose a PIso with a PIso

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, D> compose(other: PPrism<in A, out B, out C, in D>): PPrism<S, T, C, D>

Compose a PPrism with another PPrism

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 infix fun <C, D> composeLazy(other: () -> PTraversal<in A, out B, out C, in D>): PTraversal<S, T, C, D>
Link copied to clipboard
infix fun <S, T, A, B, C, D> PLens<S, T, A?, B?>.composeNull(other: PLens<A, B, C, D>): PLens<S, T, C?, D?>

Compose two lenses, where the first one has a nullable focus, keeping the nullability in the types.

Link copied to clipboard
fun <T, S, A> Traversal<T, S>.every(tr: Traversal<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
open fun exists(source: S, predicate: (focus: A) -> Boolean): Boolean

Check whether at least one element satisfies the predicate.

Link copied to clipboard
fun <S, A> Optional<S, A>.filter(predicate: (A) -> Boolean): Optional<S, A>

Focuses on the value only if the predicate is true.

fun <S, A> Traversal<S, A>.filter(predicate: (A) -> Boolean): Traversal<S, A>

Focuses on those values for which the predicate is true.

Link copied to clipboard
@JvmName(name = "filterNonEmptyList")
fun <T, A> Traversal<T, NonEmptyList<A>>.filterIndex(predicate: Predicate<Int>): Traversal<T, A>
@JvmName(name = "filterChars")
fun <T> Traversal<T, String>.filterIndex(predicate: Predicate<Int>): Traversal<T, Char>
fun <T, A> Traversal<T, List<A>>.filterIndex(predicate: Predicate<Int>): Traversal<T, A>
@JvmName(name = "filterValues")
fun <T, K, A> Traversal<T, Map<K, A>>.filterIndex(predicate: Predicate<K>): Traversal<T, A>
@JvmName(name = "filterSequence")
fun <T, A> Traversal<T, Sequence<A>>.filterIndex(predicate: Predicate<Int>): Traversal<T, A>

fun <T, S, I, A> Traversal<T, S>.filterIndex(filter: FilterIndex<S, I, A>, predicate: Predicate<I>): Traversal<T, A>

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

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(): PIso<Pair<S, C>, Pair<T, C>, Pair<A, C>, Pair<B, C>>

Create a pair of the PIso 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(initial: A, combine: (A, A) -> A, source: S): A

Fold using the given initial value and combine function.

Link copied to clipboard
open override fun <R> foldMap(initial: R, combine: (R, R) -> 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 PIso

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
open fun getAll(source: S): List<A>

Get all targets of the Traversal

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 Optional or null if the is not there

Link copied to clipboard
@JvmName(name = "indexNonEmptyList")
fun <T, A> Optional<T, NonEmptyList<A>>.index(index: Int): Optional<T, A>
@JvmName(name = "indexString")
fun <T> Optional<T, String>.index(index: Int): Optional<T, Char>
fun <T, A> Optional<T, List<A>>.index(index: Int): Optional<T, A>
@JvmName(name = "indexValues")
fun <T, K, A> Optional<T, Map<K, A>>.index(key: K): Optional<T, A>
@JvmName(name = "indexSequence")
fun <T, A> Optional<T, Sequence<A>>.index(index: Int): Optional<T, A>
@JvmName(name = "indexNonEmptyList")
fun <T, A> Traversal<T, NonEmptyList<A>>.index(index: Int): Traversal<T, A>
@JvmName(name = "indexString")
fun <T> Traversal<T, String>.index(index: Int): Traversal<T, Char>
fun <T, A> Traversal<T, List<A>>.index(index: Int): Traversal<T, A>
@JvmName(name = "indexValues")
fun <T, K, A> Traversal<T, Map<K, A>>.index(key: K): Traversal<T, A>
@JvmName(name = "indexSequence")
fun <T, A> Traversal<T, Sequence<A>>.index(index: Int): Traversal<T, A>

fun <T, S, I, A> Optional<T, S>.index(idx: 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> Traversal<T, S>.index(idx: 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
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(): PIso<Either<S, C>, Either<T, C>, Either<A, C>, Either<B, C>>

Create a sum of the PIso and a 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 fun liftNullable(f: (focus: A) -> B): (source: S) -> T?

Lift a function f: (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 polymorphically the focus of a PIso with a function

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
fun <S, A> Traversal<S, A>.onceOrMore(traversal: Traversal<A, A>): Traversal<S, A>
Link copied to clipboard
open operator fun <C, D> plus(other: PIso<in A, out B, out C, in D>): PIso<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: PPrism<in A, out B, out C, in D>): PPrism<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 fun reverse(): PIso<B, A, T, S>

Reverse a PIso: the source becomes the target and the target becomes the source

Link copied to clipboard
abstract override fun reverseGet(focus: B): T

Get the modified focus of a PIso

Link copied to clipboard
open override fun <C> right(): PIso<Either<C, S>, Either<C, T>, Either<C, A>, Either<C, B>>

Create a sum of a type C and the PIso

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

Create a pair of a type C and the PIso

Link copied to clipboard
open fun set(b: B): T

Set polymorphically the focus of a PIso with a value

open override fun set(source: S, focus: B): T

Set the focus of a PPrism with a value

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 <S1, T1, A1, B1> split(other: PIso<S1, T1, A1, B1>): PIso<Pair<S, S1>, Pair<T, T1>, Pair<A, A1>, Pair<B, B1>>

Pair two disjoint PIso

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
operator fun <T, A, B> PTraversal<T, T, A, B>.times(other: PTraversal<T, T, A, B>): PTraversal<T, T, A, B>

Traversal that aggregates the elements of two other traversals.

Link copied to clipboard
fun <S, A> Traversal<S, A>.zeroOrMore(traversal: Traversal<A, A>): Traversal<S, A>