2 unstable releases

0.2.0 Dec 19, 2021
0.1.0 Oct 6, 2021

#516 in Rust patterns

Download history 43/week @ 2022-06-01 21/week @ 2022-06-08 35/week @ 2022-06-15 46/week @ 2022-06-22 22/week @ 2022-06-29 23/week @ 2022-07-06 28/week @ 2022-07-13 30/week @ 2022-07-20 33/week @ 2022-07-27 52/week @ 2022-08-03 56/week @ 2022-08-10 70/week @ 2022-08-17 50/week @ 2022-08-24 51/week @ 2022-08-31 74/week @ 2022-09-07 74/week @ 2022-09-14

263 downloads per month
Used in plateau

MIT/Apache

13KB
197 lines

itermore

Crates.io Version Docs.rs Latest

More iterator adaptors.

🚀 Getting started

Add the following to your Cargo manifest.

[dependencies]
itermore = "0.2"

And bring the [IterMore] trait into scope

use itermore::IterMore;

🤸 Usage

The following additional iterator methods are provided.

next_array

let mut data = 1..5;
let [x, y] = data.next_array().unwrap();
assert_eq!(x, 1);
assert_eq!(y, 2);

The following adaptors are provided.

array_chunks

Similar to slice::array_chunks but for any iterator.

Returns an iterator over N elements of the iterator at a time.

let data = [1, 1, 2, -2, 6, 0, 3, 1];
//          ^-----^  ^------^
for [x, y, z] in data.iter().array_chunks() {
    let sum = x + y + z;
    assert_eq!(sum, 4);
}

array_windows

Similar to slice::array_windows but for any iterator.

Returns an iterator over all contiguous windows of length N. The windows overlap.

let data = [10, 8, 6, 4];
//          ^---^
//              ^--^
//                 ^--^
for [x, y] in data.iter().array_windows() {
    assert_eq!(x - y, 2);
}

License

Licensed under either of

at your option.

No runtime deps