POptionalGetter

interface POptionalGetter<S, T, A> : Fold<S, A>

An OptionalGetter is an optic that allows into a structure and querying an optional focus.

Parameters

S

the source of a POptional

T

the modified source of a POptional

A

the focus of a POptional

object Companion

Functions

open fun all(source: S, predicate: (A) -> Boolean): Boolean

Check if all targets satisfy the predicate

open fun any(source: S, predicate: (A) -> Boolean): Boolean

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

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

Join two Fold with the same target

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 fun combineAll(M: Monoid<A>, source: S): A

Alias for fold.

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: POptionalGetter<in A, T, out C>): POptionalGetter<S, T, C>
open fun exists(source: S, predicate: (A) -> Boolean): Boolean

Check whether at least one element satisfies the predicate.

open fun findOrNull(source: S, predicate: (A) -> Boolean): A?

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

open fun <C> first(): POptionalGetter<Pair<S, C>, Pair<T, C>, Pair<A, C>>

Create a product of the POptionalGetter and a type C

open fun firstOrNull(source: S): A?

Get the first target or null

open fun fold(M: Monoid<A>, source: S): A

Fold using the given Monoid instance.

open override fun <R> foldMap(    M: Monoid<R>,     source: S,     map: (A) -> R): R

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

open fun getAll(source: S): List<A>

Get all targets of the Fold

abstract fun getOrModify(source: S): Either<T, A>

Get the focus of an OptionalGetter or return the original value while allowing the type to change if it does not match

open fun getOrNull(source: S): A?

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

open fun isEmpty(source: S): Boolean

Check if there is no target

open fun isNotEmpty(source: S): Boolean

Check if there is at least one target

open fun lastOrNull(source: S): A?

Get the last target or null

open fun <C> left(): Fold<Either<S, C>, Either<A, C>>

Create a sum of the Fold and a type C

open operator fun <C> plus(other: Fold<in A, out C>): Fold<S, C>
open operator fun <C, D> plus(other: POptionalGetter<in A, T, out C>): POptionalGetter<S, T, C>
open fun <C> right(): Fold<Either<C, S>, Either<C, A>>

Create a sum of a type C and the Fold