-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Cases #1
Comments
Iterators are not generically reversible, so this proposal does not seek to add anything to Iterator.prototype. |
This repo seems still empty? |
indeed; we haven't updated it yet. |
Got some more concrete use cases for reversible iterators: https://es.discourse.group/t/bidirectional-iterators/339 My proposal there is different from this, but anything functionally equivalent to that (like adding a |
@isiahmeadows There are some differences in different languages, especially "next_back" (Rust) vs "previous" (Java, Kotlin) vs separate reverse iterator (Clojure and the current state of this proposal ), for example,
r.next() // {value:1}
r.next() // {value:2}
r.previous() // {value:1}
r.previous() // {done: true}
r.next() // {value:1}
r.next() // {value:2}
r.next() // {value:3}
r.next() // {value:4}
r.next() // {done:true}
r.next() // {done:true}
r.previous() // {value:4}
r.next() // {value:1}
r.next() // {value:2}
r.next_back() // {value:4}
r.next() // {value:3}
r.next_back() // {done:true} Your proposal mix the semantics of Another important question is how generators could support either of those? Separate reverse iterator is simple, u just write another generator. If Actually, I wrote an idea about that, it use |
@hax It doesn't truncate - it just starts in a different spot. It's otherwise functionally identical to Java's. Do want to reiterate I'm not beholden to this idea, and I'm still open to alternatives. |
I'm interested in joining this conversation. I would like for iter-tools to support reverse iteration. The simplest use case I can think of is making it possible to write an O(1) |
My personal thought is that the best implementation would be one which does not define any new kind of iterator at all. Not Lee's In such a scenario the only changes to the spec would be adding EDIT: moving this train of thought back the the discussion board as it no longer matches the issue. |
As @aklein mentioned, there doesn't seem to be much sense in reversing a Set.
For the other suggested use case, as an iterator prototype method, how would it be possible to have a general
.reverse()
? (i.e. you can't buffer all the values since if may be infinite).The text was updated successfully, but these errors were encountered: