bearophile <bearophileh...@lycos.com> wrote:

If (as usual) you don't want to implement this as a new D feature, I presume something like a PartialTemplate/StaticCurry/StaticPartialApplication is writeable in the standard library:

import std.typecons, std.functional, std.array;

auto optArg(alias pred, alias fn, Range)(Range r) {
    alias binaryFun!pred predicate;
    alias unaryFun!fn func;

    auto result = tuple(r.front, func(r.front));
    foreach (e; r) {
        auto tmp = func(e);
        if (predicate(e, result[1]))
            result = tuple(e, tmp);
    }
}

void main() {
    alias PartialTemplate!(optArg, "a < b") minArg;
    alias PartialTemplate!(minArg, "a") foo;
    assert(foo([5, 2, 1, 3]) == tuple(1, 1));
}

dranges has something like this:
http://svn.dsource.org/projects/dranges/trunk/dranges/docs/templates.html
see CurryTemplate

--
Simen

Reply via email to