iterator-ext

Crates.ioiterator-ext
lib.rsiterator-ext
version0.2.1
sourcesrc
created_at2021-05-02 06:53:00.536422
updated_at2022-01-02 18:32:09.487113
descriptionAn extension to Rust's Iterator
homepagehttps://github.com/jerry73204/iterator-ext
repositoryhttps://github.com/jerry73204/iterator-ext.git
max_upload_size
id392129
size27,097
(jerry73204)

documentation

https://docs.rs/iterator-ext/

README

iterator-ext: An extension to Rust's Iterator trait.

Usage

The crate provides the IteratorExt trait extends the capability of those types that implements Iterator. It provides try_filter(), try_flatten() and more fallible adaptors that are analogous to those of Iterator.

The example demonstrates the usage of the adaptors. It accumulates the values from 0 to 9, and keeps only even outcomes. It raises error when the accumulation exceeds 10.

use iterator_ext::IteratorExt;
//!
let results: Vec<_> = (0..10)
    .map(Ok)
    .try_scan(0, |acc, val| {
        *acc += val;
        if *acc <= 10 {
            Ok(Some(*acc))
        } else {
            Err("exceed limit")
        }
    })
    .try_filter(|val| Ok(val % 2 == 0))
    .collect();
//!
assert_eq!(results, vec![Ok(0), Ok(6), Ok(10), Err("exceed limit")]);

License

MIT license. See LICENSE.txt file.

Commit count: 11

cargo fmt