iterextd

Crates.ioiterextd
lib.rsiterextd
version0.7.0
sourcesrc
created_at2024-02-13 10:04:08.805295
updated_at2024-10-04 18:49:54.570514
descriptionThis trait provides additional methods for working with iterators, enhancing their functionality.
homepagehttps://github.com/pic16f877ccs/iterextd
repositoryhttps://github.com/pic16f877ccs/iterextd
max_upload_size
id1138322
size235,384
(pic16f877ccs)

documentation

README

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.

Commit count: 54

cargo fmt