iter.reduce(fn)

Build Status Latest Version

This crate gives Iterators a reduce function that is similar to fold but without an initial value. The function returns None if the iterator is empty and Some(value) otherwise. This matches the distinction between reduce and fold in Scala.

Usage

```rust extern crate reduce; use reduce::Reduce;

// Reduce a non-empty iterator into Some(value) let v = vec![1usize, 2, 3, 4, 5]; let sum = v.intoiter().reduce(|a, b| a + b); asserteq!(Some(15), sum);

// Reduce an empty iterator into None let v = Vec::::new(); let sum = v.intoiter().reduce(|a, b| a + b); asserteq!(None, sum); ```

Dependency

Reduce is available on crates.io. Use the following in Cargo.toml:

toml [dependencies] reduce = "^0.1"

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Reduce by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.