iter-scanb

Crates.ioiter-scanb
lib.rsiter-scanb
version0.3.1
sourcesrc
created_at2024-09-29 13:49:58.004742
updated_at2024-10-19 09:25:20.741245
descriptionExtend Iterator::scan, but use B, instead of Option
homepage
repositoryhttps://github.com/A4-Tacks/iter-scanb-rs
max_upload_size
id1390869
size7,509
A4-Tacks (A4-Tacks)

documentation

README

Like the Iterator::scan, but use B, instead of Option<B>, which can bring better size_hint and ergonomics.

At the same time, it will also be able to implement ExactSizeIterator and FusedIterator

Examples

use iter_scanb::IterScanB;
let a = [1, 2, 3, 4];

let mut iter = a.iter().scanb(1, |state, &x| {
    *state *= x;
    -*state
});

assert_eq!(iter.next(), Some(-1));
assert_eq!(iter.next(), Some(-2));
assert_eq!(iter.next(), Some(-6));
assert_eq!(iter.next(), Some(-24));
assert_eq!(iter.next(), None);

Like the

let a = [1, 2, 3, 4];

let mut iter = a.iter().scan(1, |state, &x| {
    *state *= x;
    Some(-*state)
});

assert_eq!(iter.next(), Some(-1));
assert_eq!(iter.next(), Some(-2));
assert_eq!(iter.next(), Some(-6));
assert_eq!(iter.next(), Some(-24));
assert_eq!(iter.next(), None);
Commit count: 16

cargo fmt