std.gregorian contribution

Philippe Sigaud philippe.sigaud at
Mon May 17 12:55:42 PDT 2010

On Mon, May 17, 2010 at 19:44, Andrei Alexandrescu <
SeeWebsiteForEmail at> wrote:

> First, you may want to follow the model set by splitter() instead of
> split() when defining unjoin(). This is because split() allocates memory
> whereas splitter splits lazily so it doesn't need to. If you do want
> split(), just call array(splitter()).
> Second, there is an ambiguity between splitting using a string as separator
> and splitting using a set of characters as separator. This could be solved
> by simply using different names:
> string str = ...;
> foreach (splitByOneOf(str, "; ")) { ... }
> foreach (splitter(str, "; ")) { ... }
I personally use a predicate, isOneOf(some range). It's curried, to it
produces the 'real' predicate which returns true when its input is in the

It's something like this:

bool delegate(ElementType!R) isOneOf(R)(R range) if (isInputRange!R)
    auto r = array(range);
    return (ElementType!R e) { return !find(assumeSorted(r), e).empty;};

It's been a long time since I used std.algo.find. Is it efficient to sort
what will be most of the time a very short array? Maybe !find(range,e) is



One nice outcome is that we can then reuse the same pattern in other
> signatures.

Indeed, and for many things: filtering, stopping iterations (takeWhile,
unfoldWhile), splitting...
And, of course, taking the negation not!isOneOf => isNotIn(";,/")

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Digitalmars-d mailing list