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

Add PeekMap and adaptors::peek_map #809

Closed MiguelX413 closed 10 months ago

MiguelX413 commented 10 months ago

This is my first pull request to this project so I would appreciate feedback. I will add documentation soon.

Philippe-Cholet commented 10 months ago

Sidenote: CI only failed because of missing documentation (and missing new tests).

Hi. I'm still writing the CONTRIBUTING.md file in #767 but you might find its draft interesting.

I'm first wondering if it is useful enough to be integrated? Do you have an usecase example? Maybe it should be proposed to libcore first?

And what would be the alternative with the current iterator+itertools? For now, all I see is use "batching" (which is definitely not obvious and the size hint info would be lost).

iterator.peekable().batching(|it| it.next().map(|x| f(x, it.peek())))

(It makes me think of MapWindows<N=2> but different, and a bit of #771.)

EDIT: I think it could be PeekMap<I, F> (no third type) by deleting F constraint on PeekMap definition.

MiguelX413 commented 10 months ago

I'll close this while https://github.com/rust-lang/rust/pull/118474 is in progress.