rust-itertools / itertools

Extra iterator adaptors, iterator methods, free functions, and macros.
https://docs.rs/itertools/
Apache License 2.0
2.72k stars 309 forks source link

Accumulate iterator adapter for rust itertools (like itertools.accumulate in Python itertools) #705

Open evan0greenup opened 1 year ago

evan0greenup commented 1 year ago

I don't find iterator adapter like itertools.accumulate(iterable[, func, *, initial=None]) in Rust itertools.

It would be nice to add it in.

phimuemue commented 1 year ago

Isn't this scan?

Philippe-Cholet commented 1 year ago

Yes it very similar to scan but it's not very obvious at first look. With initial=0 and the default func the addition.

(1..8).scan(0, |x, y| { *x += y; Some(*x) })

while people from coming Python would expect something more like

(1..8).some_name(0, |x, y| x + y)

Like in #147

EDIT: Playground example of accumulate[_add] functions.