#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

#1103 in Rust patterns

Download history 181/week @ 2024-09-23 482/week @ 2024-09-30 151/week @ 2024-10-14 20/week @ 2024-10-21 3/week @ 2024-11-04

174 downloads per month

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