Crates.io | iter-scanb |
lib.rs | iter-scanb |
version | 0.3.1 |
source | src |
created_at | 2024-09-29 13:49:58.004742 |
updated_at | 2024-10-19 09:25:20.741245 |
description | Extend Iterator::scan, but use B, instead of Option |
homepage | |
repository | https://github.com/A4-Tacks/iter-scanb-rs |
max_upload_size | |
id | 1390869 |
size | 7,509 |
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
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);