Crates.io | precog_iter |
lib.rs | precog_iter |
version | 0.5.3 |
source | src |
created_at | 2019-06-04 16:40:54.664592 |
updated_at | 2019-06-04 19:50:59.914625 |
description | An iterator adapter that returns the equivalent of `(iter.next(), iter.peek())`. |
homepage | |
repository | https://github.com/ChrisDenton/precog_iter |
max_upload_size | |
id | 138948 |
size | 21,327 |
An iterator adapter that returns the equivalent of (iter.next(), iter.peek())
.
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;
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);
Licensed under either of
at your option.
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.