# Getter

fun interface Getter<S, A> : Fold<S, A> (source)

A Getter is an optic that allows to see into a structure and getting a focus.

A Getter can be seen as a get function:

• `get: (S) -> A` meaning we can look into an `S` and get an `A`

#### Parameters

S

the source of a Getter

A

the focus of a Getter

object Companion

## Functions

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

Check if all targets satisfy the predicate

open fun any(source: S, predicate: (focus: 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 <C> choice(other: Getter<C, A>): Getter<Either<S, C>, A>

Join two Getter with the same focus

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 fun exists(source: S, predicate: (focus: A) -> Boolean): Boolean

Check whether at least one element satisfies the predicate.

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

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

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

Create a product of the Getter 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

abstract fun get(source: S): A

Get the focus of a Getter

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

Get all targets of the Fold

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 override fun <C> left(): Getter<Either<S, C>, Either<A, C>>

Create a sum of the Getter and type C

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 override fun <C> right(): Getter<Either<C, S>, Either<C, A>>

Create a sum of type C and the Getter

open fun <C> second(): Getter<Pair<C, S>, Pair<C, A>>

Create a product of type C and the Getter

open fun size(source: S): Int

Calculate the number of targets

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

Pair two disjoint Getter

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

Zip two Getter optics with the same source S

## Extensions

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.