-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Filter(f, Task) is fundamentally broken #6224
Comments
Here's an interesting idea. We could require stateful iterators to be able to repeatedly return the current value without side effects, e.g.:
The integer is only one possible implementation, but used as an example for clarity. |
bump; I'm working on an HTML parsing library and it would be really convenient to be able to define tree traversal functions on HTML elements by just returning tasks, but I'm hesitant to do so because of this :/ |
Jeff's idea here works fine; if it's not a huge performance hit I'm all in favor of changing to that. Even if it's slightly slower, better to be correct. |
fixed by 1f5ed7a |
👏 💯 I had thought about fixing it via Filter but this is almost certainly better than whatever I would have come up with. Thanks! |
An issue with filtering a Task was raised here:
https://groups.google.com/forum/#!topic/julia-users/gn0Rj9XexNk
The immediate patch I tried is to invert the predicate like this:
However, this is not correct – the predicate direction was actually right: keep values for which the predicate is true. Accordingly, this change causes our functional tests to fail:
To really fix this issue, we need to keep the previously yielded state and value – specifically for iterables like tasks and IO streams where the state is really simply the state of the iterable object itself and the functional state is a dummy. We could make that change, but it's really awkward, annoying and inefficient – and makes it impossible to avoid some kind of unintuitiveness since advancing the iterator happens before people expect it too. Perhaps we should really consider changing the iteration protocol as brought up in #6125. All of this is highly exacerbated when composed with lazy iteration like Filter, Zip, etc
The text was updated successfully, but these errors were encountered: