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) -> BParameters
faValue to be folded.
bInitial value for the folding process.
fFolding function.
Return Value
Summary value resulting from the folding process.
-
Lazily folds a value to a summary value from right to left.
Declaration
Parameters
faValue to be folded.
bInitial value for the folding process.
fFolding 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
faValue 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
faValue to be folded.
fTransforming function.
gFolding function.
Return Value
Optional summary value resulting from the folding process. It will be an
Option.noneif 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
faValue to be folded.
fTransforming function.
gFolding function.
Return Value
Optional summary value resulting from the folding process. It will be an
Option.noneif 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
faValue to be folded.
fFolding 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
faValue to be folded.
fFolding 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
faValue 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
Monoidinstance and folds them using the empty and combine methods of suchMonoidinstance.Declaration
Parameters
faValue to be transformed and folded.
fTransforming 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
faStructure of values.
fTransforming 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
fgaStructure 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
faStructure of values where the element matching the predicate needs to be found.
fPredicate.
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) -> BoolParameters
faStructure of values where the element matching the predicate needs to be found.
predicatePredicate.
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) -> BoolParameters
faStructure of values where all elements should match the predicate.
predicatePredicate.
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>) -> BoolParameters
faStructure of values.
Return Value
falseif the structure contains any value,trueotherwise. -
nonEmpty(_:)Extension methodChecks if a structure of values is not empty.
Declaration
Swift
static func nonEmpty<A>(_ fa: Kind<Self, A>) -> BoolParameters
faStructure of values.
Return Value
trueif the structure contains any value,falseotherwise. -
foldM(_:_:_:)Extension methodPerforms a monadic left fold from the source context to the target monad.
Declaration
Parameters
faStructure of values.
bInitial value for the fold.
fFolding 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
Monoidinstance to combine them.Declaration
Parameters
faStructure of values.
fTrasnforming 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
faStructure of values.
indexIndexed position of the element to retrieve.
Return Value
A value if there is any at the given position, or
Option.noneotherwise. -
count(_:)Extension methodCounts how many elements a structure contains.
Declaration
Swift
static func count<A>(_ fa: Kind<Self, A>) -> Int64Parameters
faStructure 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
Install in Dash
Foldable Protocol Reference