Generic abstractions for combining and nesting reduction patterns for iterables.
The main entry point to this library is Reduce::reduce_with, which can be called
on any Iterator, and is very similar to Iterator::reduce, but uses a generic
implementation of a Reductor for the reduction logic.
The following examples shows some of the basic building blocks from which reductor
enables building more complex patterns:
use ;
let iter = 0..10;
let Sum = iter.clone.;
let Product = iter.clone.;
let Count = iter.clone.reduce_with;
assert_eq!;
assert_eq!;
assert_eq!;
let Max = iter.clone.;
let Min = iter.clone.;
assert_eq!;
assert_eq!;
Notice that unlike Sum and Product, Min and Max won't reduce
an empty iterator into the default value. This mirrors the way Iterator::max
returns an Option<T>, unlike Iterator::sum.
Now, let's combine two Reductors to reduce an iterator that produces a pair of values:
use ;
let iter = 0..10;
let = iter
.clone
.map
.;
assert_eq!;
assert_eq!;
Another abstraction provided by this library is ReductorPair, which allows
reducing an iterator producing a single value by a pair of Reductors, in tandem.
use ;
let iter = 0..10;
let ReductorPair = iter
.clone
.map
..unwrap;
assert_eq!;
assert_eq!;
These constructs allow building very complex iterator loops that compose numerous reductions into a single set of results.
use ;
let iter = .filter_map;
let ReductorPair = iter
.clone
..unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;