rust-unofficial / patterns

A catalogue of Rust design patterns, anti-patterns and idioms
https://rust-unofficial.github.io/patterns/
Mozilla Public License 2.0
7.95k stars 362 forks source link

Fold pattern discussion should mention Iterator::scan #149

Open NilSet opened 3 years ago

NilSet commented 3 years ago

In the Fold page, it mentions how similar it is to Iterator::map but is more flexible. It should also mention Iterator::scan which allows carrying state forward across iterations, solving the earlier nodes can affect the operation on later nodes use case. In fact, a folder as described might make a good state object to carry through a scan.

I wonder if this pattern could be renamed to Scanner or something, since as mentioned in #54 the name Fold is mixed up with other programming concepts right next door to it.