Implementations of takeWhile, drop, and dropWhile.#147
Implementations of takeWhile, drop, and dropWhile.#147jmdavis wants to merge 8 commits intodlang:masterfrom
Conversation
This partially fulfills http://d.puremagic.com/issues/show_bug.cgi?id=5645 I'm not sure if it makes any sense to implement the slice function asked for in there though. But then again, I also don't quite understand what it does either. Those two items probably should have been on separate enhancement requests.
std/range.d
Outdated
There was a problem hiding this comment.
@property? (pure nothrow const @safe too, if you like :) )
There was a problem hiding this comment.
return _done; is pure nothrow @safe no matter if the range's annotation. But you're right, it's better to let the compiler infer that.
|
Any more comments on this before I merge it in? |
I also made it so that takeWhile's Result isn't static anymore. It didn't work with delegates that way.
|
Any more comments, suggestions, or objections? I'd like to merge this in as it stands, and Andrei now seems to be okay with So, does anyone have a good reason as to why any of these shouldn't be merged into Phobos? |
|
Upon looking at this again, I think this addition doesn't pull its weight. takeWhile is isomorphic with until, drop is a lossy version of popFrontN, and dropWhile is isomorphic with find. Jonathan, that's not to diminish your work -- sorry. You may want to put this up for a community vote or something. My opinion is that we don't need such redundancy in std.algorithm. |
|
Well, if you can do exactly the same thing as So, if you really think that |
|
You may want to ask for a vote on drop. I'd use (popFrontN(r), r) for doing what drop does, and overall I prefer popFrontN because it returns the number of elements popped - information which is lost with drop. |
|
I'll ask for a vote on it then. On a related note, we might want to look at how we can improve the documentation to make it clearer as to what functions can be used to do the same thing that other languages do. For instance, |
Fix warnings in dustmite
This fulfills http://d.puremagic.com/issues/show_bug.cgi?id=4535 and partially fulfills http://d.puremagic.com/issues/show_bug.cgi?id=5645
dropanddropWhilein particular should help allow a more functional style of programming when dealing with ranges.