//arrow-optics/arrow.optics/Fold

Fold

common interface Fold<S, A>

A Fold is an optic that allows to focus into structure and get multiple results.

Fold is a generalisation of an instance of Foldable and is implemented in terms of foldMap.

Parameters

common

   
S the source of a Fold
A the target of a Fold

Types

Name Summary
Companion common object Companion

Functions

Name Summary
all common open fun all(source: S, predicate: (A) -> Boolean): Boolean
Check if all targets satisfy the predicate
any common open fun any(source: S, predicate: (A) -> Boolean): Boolean
Returns true if at least one focus matches the given predicate.
choice common open infix fun <C> choice(other: Fold<C, A>): Fold<Either<S, C>, A>
Join two Fold with the same target
combineAll common open fun combineAll(M: Monoid<A>, source: S): A
Alias for fold.
compose common open infix fun <C> compose(other: Fold<in A, out C>): Fold<S, C>
Compose a Fold with a Fold
exists common open fun exists(source: S, predicate: (A) -> Boolean): Boolean
Check whether at least one element satisfies the predicate.
findOrNull common open fun findOrNull(source: S, predicate: (A) -> Boolean): A?
Find the first element matching the predicate, if one exists.
firstOrNull common open fun firstOrNull(source: S): A?
Get the first target or null
fold common open fun fold(M: Monoid<A>, source: S): A
Fold using the given Monoid instance.
foldMap common abstract 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
getAll common open fun getAll(source: S): List<A>
Get all targets of the Fold
isEmpty common open fun isEmpty(source: S): Boolean
Check if there is no target
isNotEmpty common open fun isNotEmpty(source: S): Boolean
Check if there is at least one target
lastOrNull common open fun lastOrNull(source: S): A?
Get the last target or null
left common open fun <C> left(): Fold<Either<S, C>, Either<A, C»
Create a sum of the Fold and a type C
plus common open operator fun <C> plus(other: Fold<in A, out C>): Fold<S, C>
right common open fun <C> right(): Fold<Either<C, S>, Either<C, A»
Create a sum of a type C and the Fold
size common open fun size(source: S): Int
Calculate the number of targets

Inheritors

Name
PEvery
Getter
PIso
PLens
POptional
PPrism

Extensions

Name Summary
at common 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.
every common 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
index common 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
some common 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>

Do you like Arrow?

Arrow Org
<