More windowing functions for iterators

There is an ongoing effort to introduce .map_windows into iterators.

However, I was wondering if Iterators would benefit for windowing functions, e.g fold_windows, like fold it contains an accumulator and current window, which you can use for a variety of things like parsing, prehaps .any_windows or several type of regular vector/slice equivalent for windows would be useful, I certainly have use cases for parsing.

As always it's about trade-offs. any_windows() can be implemented as map_windows() returning bool and then any().

Wouldn't that be more iterations, because an any() can return true at the first instance a predicate is correct, maping to bools then looking for any, will work but you are iterating over all the data when in reality you just need to find the first window that matches the predicate.

Iterators are lazy / on-demand -- the map will only process as many items as the any requests.

1 Like