<br><div class="gmail_quote">On Mon, May 17, 2010 at 19:44, Andrei Alexandrescu <span dir="ltr">&lt;<a href="mailto:SeeWebsiteForEmail@erdani.org">SeeWebsiteForEmail@erdani.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div><div></div><br></div>
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&#39;t need to. If you do want split(), just call array(splitter()).<br>

<br>
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:<br>
<br>
string str = ...;<br>
foreach (splitByOneOf(str, &quot;; &quot;)) { ... }<br>
foreach (splitter(str, &quot;; &quot;)) { ... }<br>
<br></blockquote><div><br>I personally use a predicate, isOneOf(some range). It&#39;s curried, to it produces the &#39;real&#39; predicate which returns true when its input is in the range.<br><br>It&#39;s something like this:<br>
<br>bool delegate(ElementType!R) isOneOf(R)(R range) if (isInputRange!R)<br>{<br>    auto r = array(range);<br>    sort(r);<br>    return (ElementType!R e) { return !find(assumeSorted(r), e).empty;}; <br>}<br><br>It&#39;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 enough.<br><br>Usage:<br><br>     splitBy!(isOneOf(&quot;;,/&quot;))(rangeToBeSplitted)<br><br><br><br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

One nice outcome is that we can then reuse the same pattern in other signatures.<font color="#888888"></font></blockquote><div><br>Indeed, and for many things: filtering, stopping iterations (takeWhile, unfoldWhile), splitting...<br>
And, of course, taking the negation not!isOneOf =&gt; isNotIn(&quot;;,/&quot;)<br><br><br>Philippe <br></div></div>