#iterator #peek #next #iterator-adapter #precog #precognition

yanked precog_iter

An iterator adapter that returns the equivalent of (iter.next(), iter.peek())

0.5.3 Jun 4, 2019
0.5.2 Jun 4, 2019
0.5.1 Jun 4, 2019
0.5.0 Jun 4, 2019

#25 in #iterator-adapter

MIT/Apache

9KB
71 lines

precog_iter

Crates.io Docs.rs License: MIT/Apache-2.0 Build status

An iterator adapter that returns the equivalent of (iter.next(), iter.peek()).

Installation

Add a dependency to your Cargo.toml.

[dependencies]
precog_iter = "0.5"

Then use the trait in your main.rs or lib.rs file.

use precog_iter::Precognition;

Usage

use precog_iter::Precognition;

let mut iter = "ABAC".chars()
    .precog()
    .filter_map(|(codepoint, next)| {
        // Remove codepoint if followed by 'C'.
        match next {
            Some(n) if n == 'C' => {
                None
            }
            _ => Some(codepoint)
        }
    });

assert_eq!(iter.next(), Some('A'));
assert_eq!(iter.next(), Some('B'));
// The second 'A' has been filtered
assert_eq!(iter.next(), Some('C'));
assert_eq!(iter.next(), None);

License

Licensed under either of

at your option.

Contribution

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

No runtime deps