itertools icon indicating copy to clipboard operation
itertools copied to clipboard

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

Open evan0greenup opened this issue 1 year ago • 2 comments

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

It would be nice to add it in.

evan0greenup avatar Jun 18 '23 04:06 evan0greenup

Isn't this scan?

phimuemue avatar Jun 18 '23 05:06 phimuemue

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.

Philippe-Cholet avatar Jun 18 '23 08:06 Philippe-Cholet