[Issue 4535] std.range could have a takeWhile!pred(range) function

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Aug 19 15:46:36 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4535



--- Comment #3 from Philippe Sigaud <philippe.sigaud at gmail.com> 2010-08-20 00:46:32 CEST ---
(In reply to comment #1)
> Doesn't std.algorithm.until pretty much do what you want?

Hmm.
I see until() is templated on the predicate. I guess most of the time, I can
rewrite my predicates to use until.

auto t = takeWhile!"a*a>10"(someValues);
auto u = until!"a*a>b"(10, someValues); // hey, b is 10, a will be elements
from someValues. Is that clear?

I personally find takeWhile to be more readable. Maybe I'm biased due to my
using it in other languages?


Also, it's cumbersome for no-arg functions:

// takes lines as long as they are not empty
auto t = takeWhile!"!a.empty"(file.byLine);
auto u = until!"!a.empty"(dummy, file.byLine);

auto t = takeWile!externalUnaryPredicate(someValues);
auto u = until!externalUnaryPredicate(??, someValues); // How do I do that?


Philippe

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list