More iterator adaptors.
Add the following to your Cargo manifest.
toml
[dependencies]
itermore = "0.1"
And bring the [IterMore
] trait into scope
rust
use itermore::IterMore;
The following adaptors are provided.
chunks
Similar to slice::chunks_exact
but for any iterator.
Returns an iterator over N
elements of the iterator at a time.
rust
let data = [1, 1, 2, -2, 6, 0, 3, 1];
// ^-----^ ^------^
for [x, y, z] in data.iter().chunks() {
let sum = x + y + z;
assert_eq!(sum, 4);
}
windows
Similar to slice::windows
but for any iterator.
Returns an iterator over all contiguous windows of length N
. The windows
overlap.
rust
let data = [10, 8, 6, 4];
// ^---^
// ^--^
// ^--^
for [x, y] in data.iter().windows() {
assert_eq!(x - y, 2);
}
Licensed under either of
at your option.