pub struct Fold<'a, M, D> { /* private fields */ }
Expand description
A representation of an arbitrary Foldable
fold.
This struct is what facilitates lazy evaluation of Fold
s, allowing them
to be chained together with other Directive
, and evaluated in a single
pass.
Where a Foldable
defines the semantics of folding over a structure,
Fold
represents an instance of a fold over that type. In other words,
Fold
is simply a pairing of a Foldable
with the Monoid
that
will be used to combine its values.
A subtle implementation detail is that we do not actually embed a
Foldable
, but rather a Directive
that outputs a Foldable
. This
is what allows us to chain Directive
s together, as the output of one
Directive
is the input to the next.
Trait Implementations§
Source§impl<'a, M: Monoid + 'static, F: Foldable<'a, M::Elem, A = M::Elem> + Send, D: Directive<Output = F> + Send> Directive for Fold<'a, M, D>
impl<'a, M: Monoid + 'static, F: Foldable<'a, M::Elem, A = M::Elem> + Send, D: Directive<Output = F> + Send> Directive for Fold<'a, M, D>
The implementation drives the evaluation of the input Directive
,
returning the input Foldable
, and then folding the given Monoid
over it.