Mehrdad:

auto groupby(alias Key = k => k, alias Value = v => v, alias Equal = (a, b) => a == b, R)(R range)
        if (isInputRange!(R))

I have not studied the semantics of this groupby, but Phobos contains a std.algorithm.group that is not too much different from the Python itertools function (there are some differences, but they are often acceptable).


auto dict(R)(R range)
{
        ElementType!(R)[typeof(ElementType!(R).init[0])] result;
        foreach (t; range) { result[t[0]] = t /* or t[1]? */; }
        return result;
}

There are various ways to design a similar function, and I think something similar is handy to have. I think I have already put an enhancement request for it in Bugzilla.


auto sorted(alias F = q{a < b}, SwapStrategy S = SwapStrategy.unstable, R)(R range)
{
        auto arr = range.array();
        arr.sort!(F, S)();
        return arr;
}

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

Bye,
bearophile

Reply via email to