Crates.io | iterextd |
lib.rs | iterextd |
version | 0.5.0 |
source | src |
created_at | 2024-02-13 10:04:08.805295 |
updated_at | 2024-06-06 08:48:34.46567 |
description | This trait provides additional methods for working with iterators, enhancing their functionality. |
homepage | https://github.com/pic16f877ccs/iterextd |
repository | https://github.com/pic16f877ccs/iterextd |
max_upload_size | |
id | 1138322 |
size | 169,146 |
Adapters that extend Iterator
functionality.
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]);
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]));
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]]);
iterextd
provides several adapters to extend the functionality of iterators in Rust.Add this to your Cargo.toml
:
[dependencies]
iterextd = "0.3.0"
This project is licensed under the MIT License.