[Issue 13940] std.algorithm.argMin
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Jan 5 13:34:06 PST 2015
https://issues.dlang.org/show_bug.cgi?id=13940
--- Comment #2 from Peter Alexander <peter.alexander.au at gmail.com> ---
(In reply to bearophile_hugs from comment #1)
> See Issue 4705 where I suggested to add to max/min an optional "key"
> argument unary function.
>
> So to find the min or max with a key of a sequence you use a reduce:
>
> someRange.reduce!(max!abs)
>
> It evaluates the key function only once for item.
In the reduce, the max!abs would be called n - 1 times, and each call to
max!abs(a, b) would involve two calls to abs, so 2(n - 1) calls total, not n
(unless I've misunderstood somewhere).
--
More information about the Digitalmars-d-bugs
mailing list