-
-
Notifications
You must be signed in to change notification settings - Fork 706
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 consume to SList #5821
Add consume to SList #5821
Conversation
A range that iterates then removes elements for which the predicate is true. An efficient combination of `filter!(pred)` and `remove`.
|
Thanks for your pull request, @thewilsonator! We are looking forward to reviewing it, and you should be hearing from a maintainer soon. Some tips to help speed things up:
Bear in mind that large or tricky changes may require multiple rounds of review and revision. Please see CONTRIBUTING.md for more information. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
to avoid `template instance consume!((e) => e < 0) cannot use local '__lambda1' as parameter to non-global template consume(alias pred)()` errors.
|
This is a good idea, but we could achieve the desired behaviour by using One could do something like this: I believe that |
|
That works but creates a new list (with allocations and copying of data), rather than mutate the old (reference semantics). The whole point is to amortise the Perhaps it would be more aptly named |
If you already create a new List, you can simply use
Yes, but the word
I get your point, but I'm not fully convinced that this is a popular operation, especially considering that std.container will hopefully get replaced / deprecated soonish. What do other people think? |
|
This seems like a lot of code for a very specific problem. What's the use case? |
|
This is a difficult and subtle API, though I see its necessity. A tricky problem with SList is that removal primitives need to access the node just before the element being removed. I think the right approach is along the lines of Then a predicated version of the function would remove by predicate, not a specific value. |
|
I like that idea much better. Will work on it tomorrow. |
|
friendly ping @thewilsonator. Any updates on this? |
|
Heh, completely forgot about it. It looks like |
|
How about adding an overload that takes a predicate? I think that's what @andralex was suggesting |
|
PR closed as stalled. If you wish to resurrect it you are welcome to do so. |
A range that iterates then removes elements for which the predicate is
true. An efficient combination of
filter!(pred)andremove.