improving the join function
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Tue Oct 12 06:53:34 PDT 2010
On 10/11/10 23:37 CDT, Daniel Gibson wrote:
> Btw: Is "join" not just a (rather trivial) generalization of reduce?
>
> auto inRange = ...; // range of char[]
> char[] sep = " ";
> auto joined = reduce!( (char[] res, char[] x) {return res~sep~x;})
> (inRange);
It is, but things are a bit messed up by empty ranges.
auto joined = inRange.empty
? reduce!( (char[] res, char[] x) {return res~sep~x;})(inRange)
: "":
Andrei
More information about the Digitalmars-d
mailing list