8 releases (breaking)
0.7.0 | Oct 4, 2024 |
---|---|
0.6.0 | Aug 16, 2024 |
0.5.0 | Jun 6, 2024 |
0.4.1 | May 17, 2024 |
0.1.0 | Feb 13, 2024 |
#634 in Algorithms
23 downloads per month
99KB
2K
SLoC
iterextd
Adapters that extend Iterator
functionality.
Example Usages
Variable step
use iterextd::IterExtd;
let logic_fn = |s: &mut usize| { if *s == 0 { *s = 1; 1 } else { *s += 1; *s } };
let iter = (0..18).step_by_fn(logic_fn);
let vec = iter.collect::<Vec<_>>();
assert_eq!(vec, vec![0, 2, 5, 9, 14]);
Collect a zeroed array
use iterextd::IterExtd;
let arr = [1u8, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let iter = arr.iter().filter(|elem| *elem % 2 == 0).copied();
let arr: (usize, [u8; 10]) = iter.collect_arr_zeroed();
assert_eq!(arr, (5, [2, 4, 6, 8, 10, 0, 0, 0, 0, 0]));
Collect windows from arrays.
use iterextd::IterExtd;
let arr = [0, 1, 2, 3, 4, 5, 6, 7];
let iter = arr.into_iter();
let iter = iter.clone().map_iters(iter.previous(1).skip(2), |self_iter, arg_iter| {
let (pre_elem, elem) = arg_iter.next()?;
Some([self_iter.next()?, pre_elem, elem])
});
let vec = iter.collect::<Vec<_>>();
assert_eq!(vec, vec![[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5 , 6, 7]]);
Features
iterextd
provides several adapters to extend the functionality of iterators in Rust.
Usage
Add this to your Cargo.toml
:
[dependencies]
iterextd = "0.6.0"
License
This project is licensed under the MIT License.
Dependencies
~1MB
~21K SLoC