What functions could be added to std.algorithm?

dsimcha dsimcha at yahoo.com
Sun Aug 1 07:02:08 PDT 2010


== Quote from Philippe Sigaud (philippe.sigaud at gmail.com)'s article
> A few hours ago, in a thread on D contracts, KennyTM~ said:
> > BTW, there should be an 'all = reduce!"a&&b"' and 'any = reduce!"a||b"' in
std.algorithm, but short-circuited.
> I agree. all() and any/some() are both easy to code, I think, and useful in many
situations.
> In D, they could work on any input range, with any predicate. As they do not
return ranges, I suggest to put them in std.algo.
> A possible implementation:
> bool all(alias pred = "a", R)(R range) if (isInputRange!R)
> {
>     foreach(elem; range)
>     {
>         if (!unaryFun!predicate(elem)) return false;
>     }
>     return true;
> }
> Yeah, I know, std.algorithm is already quite big. In fact, I'm all for cutting
it or using a (gasp) two-level hierarchy in Phobos,
> but I admit having no readily usable scheme to propose.
>  algorithm.find, for all find-related thingies
>  algorithm.sort,
> etc

Please, no.  This is why I hate Tango and Java.  It's too hard to find what you
need, and you have to write too much import declaration boilerplate.  I love
Phobos's flat, simple, even if at times sloppy, import system.  Even so, I have a
module in my personal lib that just publicly imports the 10 or so Phobos modules I
use most frequently, because even in Phobos the amount of import declaration
boilerplate is too much, but using std.all caused too many naming collisions with
modules that I don't use.


More information about the Digitalmars-d mailing list