Skip to content

Conversation

Philippe-Cholet
Copy link
Member

Related to #792
To make the CoalesceBy adaptor lazy, I use a nested option again.
This would make methods coalesce and dedup[_by][_with_count] all lazy.

But it required some preliminary adaptation because of last: iter.next().map(|v| (1, v)), in dedup_by_with_count function. Make this lazy required to delay |v| (1, v). And I therefore created structs NoCount and WithCount sharing a same behavior with the new CountItem trait.
Let me know what you think about it.

In order to make `DedupByWithCount` lazy soon, I first need to be able to make `|v| (1, v)` more generic.
Similar to what is done by `core::iter::Peekable`, a nested option is now used.
This behavior is not obvious at first glance of `Iterator::next`. In it, after `let init =`, `last` is `Some(None)` in both cases. With `try_fold`, if `iter` is not exhausted then we have `*last = Some(Some(..))` (otherwise it remains `Some(None)`).
@Philippe-Cholet Philippe-Cholet mentioned this pull request Nov 13, 2023
11 tasks
@jswrenn jswrenn modified the milestones: next, 0.12.0 Nov 14, 2023
@jswrenn jswrenn added this pull request to the merge queue Nov 25, 2023
Merged via the queue into rust-itertools:master with commit cdf12df Nov 25, 2023
@Philippe-Cholet Philippe-Cholet deleted the coalesce_by-laziness branch November 25, 2023 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants