Foldable
public protocol Foldable
Foldable describes types that have the ability to be folded to a summary value.
-
Eagerly folds a value to a summary value from left to right.
Declaration
Swift
static func foldLeft<A, B>( _ fa: Kind<Self, A>, _ b: B, _ f: @escaping (B, A) -> B) -> B
Parameters
fa
Value to be folded.
b
Initial value for the folding process.
f
Folding function.
Return Value
Summary value resulting from the folding process.
-
Lazily folds a value to a summary value from right to left.
Declaration
Parameters
fa
Value to be folded.
b
Initial value for the folding process.
f
Folding function.
Return Value
Summary value resulting from the folding process.
-
fold(_:)
Extension methodFolds a structure of values provided that its type has an instance of
Monoid
.It uses the monoid empty value as initial value and the combination method for the fold.
Parameters
fa
Value to be folded.
Return Value
Summary value resulting from the folding process.
-
reduceLeftToOption(_:_:_:)
Extension methodReduces the elements of a structure down to a single value by applying the provided transformation and aggregation funtions in a left-associative manner.
Declaration
Parameters
fa
Value to be folded.
f
Transforming function.
g
Folding function.
Return Value
Optional summary value resulting from the folding process. It will be an
Option.none
if the structure is empty, or a value if not. -
reduceRightToOption(_:_:_:)
Extension methodReduces the elements of a structure down to a single value by applying the provided transformation and aggregation functions in a right-associative manner.
Declaration
Parameters
fa
Value to be folded.
f
Transforming function.
g
Folding function.
Return Value
Optional summary value resulting from the folding process. It will be an
Option.none
if the structure is empty, or a value if not. -
reduceLeftOption(_:_:)
Extension methodReduces the elements of a structure down to a single value by applying the provided aggregation function in a left-associative manner.
Declaration
Parameters
fa
Value to be folded.
f
Folding function.
Return Value
Optional summary value resulting from the folding process.
-
reduceRightOption(_:_:)
Extension methodReduces the elements of a structure down to a single value by applying the provided aggregation function in a right-associative manner.
Declaration
Parameters
fa
Value to be folded.
f
Folding function.
Return Value
Optional summary value resulting from the folding process.
-
combineAll(_:)
Extension methodFolds a structure of values provided that its type has an instance of
Monoid
.It uses the monoid empty value as initial value and the combination method for the fold.
Parameters
fa
Value to be folded.
Return Value
Summary value resulting from the folding process.
-
foldMap(_:_:)
Extension methodTransforms the elements of a structure to a type with a
Monoid
instance and folds them using the empty and combine methods of suchMonoid
instance.Declaration
Parameters
fa
Value to be transformed and folded.
f
Transforming function.
Return Value
Summary value resulting from the transformation and folding process.
-
traverse_(_:_:)
Extension methodTraverses a structure of values, transforming them with a provided function and discarding the result of its effect.
Declaration
Swift
static func traverse_<G: Applicative, A, B>( _ fa: Kind<Self, A>, _ f: @escaping (A) -> Kind<G, B>) -> Kind<G, Unit>
Parameters
fa
Structure of values.
f
Transforming function.
Return Value
Unit in the context of the effect of the result of the transforming function.
-
sequence_(_:)
Extension methodTraverses a structure of effects, performing them and discarding their result.
Declaration
Swift
static func sequence_<G: Applicative, A, B>(_ fga: Kind<Self, B>) -> Kind<G, Unit> where B: Kind<G, A>
Parameters
fga
Structure of effects.
Return Value
Unit in the context of the effects contained in the structure.
-
find(_:_:)
Extension methodLooks for an element that matches a given predicate.
Declaration
Parameters
fa
Structure of values where the element matching the predicate needs to be found.
f
Predicate.
Return Value
A value if there is any that matches the predicate, or
Option.none
. -
exists(_:_:)
Extension methodChecks if any element in a structure matches a given predicate.
Declaration
Swift
static func exists<A>( _ fa: Kind<Self, A>, _ predicate: @escaping (A) -> Bool) -> Bool
Parameters
fa
Structure of values where the element matching the predicate needs to be found.
predicate
Predicate.
Return Value
A boolean value indicating if any elements in the structure match the predicate.
-
forall(_:_:)
Extension methodChecks if all elements in a structure match a given predicate.
Declaration
Swift
static func forall<A>( _ fa: Kind<Self, A>, _ predicate: @escaping (A) -> Bool) -> Bool
Parameters
fa
Structure of values where all elements should match the predicate.
predicate
Predicate.
Return Value
A boolean value indicating if all elements in the structure match the predicate.
-
isEmpty(_:)
Extension methodChecks if a structure of values is empty.
Declaration
Swift
static func isEmpty<A>(_ fa: Kind<Self, A>) -> Bool
Parameters
fa
Structure of values.
Return Value
false
if the structure contains any value,true
otherwise. -
nonEmpty(_:)
Extension methodChecks if a structure of values is not empty.
Declaration
Swift
static func nonEmpty<A>(_ fa: Kind<Self, A>) -> Bool
Parameters
fa
Structure of values.
Return Value
true
if the structure contains any value,false
otherwise. -
foldM(_:_:_:)
Extension methodPerforms a monadic left fold from the source context to the target monad.
Declaration
Parameters
fa
Structure of values.
b
Initial value for the fold.
f
Folding function.
Return Value
Summary value resulting from the folding process in the context of the target monad.
-
foldMapM(_:_:)
Extension methodPerforms a monadic left fold by mapping the values in a structure to ones in the target monad context and using the
Monoid
instance to combine them.Declaration
Parameters
fa
Structure of values.
f
Trasnforming function.
Return Value
Summary value resulting from the transformation and folding process in the context of the target monad.
-
get(_:_:)
Extension methodObtains a specific element of a structure of elements given its indexed position.
Parameters
fa
Structure of values.
index
Indexed position of the element to retrieve.
Return Value
A value if there is any at the given position, or
Option.none
otherwise. -
count(_:)
Extension methodCounts how many elements a structure contains.
Declaration
Swift
static func count<A>(_ fa: Kind<Self, A>) -> Int64
Parameters
fa
Structure of values.
Return Value
An integer value with the count of how many elements are contained in the structure.
-
foldK(_:)
Extension method -
reduceK(_:)
Extension method -
asArray(_:)
Extension method