#iterator #scan #adapter #extension #no-std

no-std iter-scanb

Extend Iterator::scan, but use B, instead of Option<B>

8 releases

0.3.1 Oct 19, 2024
0.3.0 Sep 30, 2024
0.2.0 Sep 30, 2024
0.1.4 Sep 30, 2024

#30 in #scan

MIT license

7KB
73 lines

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);

No runtime deps

Features