-
-
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
Add takewhile, dropwhile to iterators #33437
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of stylistic fixes needed but I agree that the functionality would be nice to have.
Fix stylistic suggestions from ararslan Co-Authored-By: Alex Arslan <[email protected]>
Should rebase on master to get the whitespace fix. Also |
Relax unionall annotations Co-Authored-By: Jeff Bezanson <[email protected]>
Thanks for the feedback and openness ! |
- [x] fix order of iterate? / ctor args / struct fields - [x] review (leaning of) type annotation
- [x] replace `x->x<k` by `<(k)` @ test - [x] replace `x->some_const` by `_->some_const` @ test - [x] remove excedentary collect @ test
- [x] fix order of ctor args / struct fields - [y] review (leaning of) type annotation - [x] redo explicitation @ IteratorSize(::Type{DropWhile}). otherwise MethodError: no method matching length was raised
- [x] replace `x->x<k` by `<(k)` @ test - [x] replace `x->some_const` by `_->some_const` @ test - [x] remove excedentary collect @ test - [/] remove pipeline @ test
Choice has been made to reimplement filter with a recoded while pred loop. State partition is determined only by the emptiness of iterator One could use Iterators.filter with Iterators.Stateful but filter erases last elem state and stateful did not revert propertly due to nextvalstate/taken machinery. Stateful needs some cleanup.
Possible Enhancement
|
Code looks good now, thanks. Just needs news and docs. |
- [x] set docs of takewhile, dropwhile - [x] set compat
- [x] fix takewhile, dropwhile test comment
news update@ new library functions
|
compat updatecompat has been set to Julia 1.4 |
Julia 1.3 is feature frozen, so the compatibility notice here should be set to 1.4. As for a NEWS item, I'd just say
|
Co-Authored-By: Alex Arslan <[email protected]>
Co-Authored-By: Alex Arslan <[email protected]>
I've updated the news and update sections according to your remarks. |
Looks like the NEWS file hasn't been updated. |
Co-Authored-By: Alex Arslan <[email protected]>
A A oneliner can do the thing. # zip variant. clone of python compress
@inline Base.Iterators.filter(markers::Union{Vector{Bool},BitVector}, s) =
(i for (m,i) in zip(markers,s) if m)
# enumerate variant. julia thing
@inline Base.Iterators.filter(markers::Union{Vector{Bool},BitVector}, s) =
(i for (n,i) in enumerate(s) if markers[n]) BenchesBench initialization using Random
bs = bitrand(10_000);
is = rand(1:100,10_000) Bench of filter (zip variant)
Bench of filter (enumerate variant)
The enumerate variant seems 10-15% faster but does not checkbounds! |
#33437 has added the two functions, but it didn't appear in the documentation.
JuliaLang#33437 has added the two functions, but it didn't appear in the documentation.
#33437 has added the two functions, but it didn't appear in the documentation.
Constating that python, ruby, rust, elixir all offer takewhile, dropwhile
And also dotnet, java, scala !
I think Julia should have them too.
IterTools.jl, and rust have been consulted.