[Issue 13940] std.algorithm.argMin

2015-01-05 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=13940

bearophile_h...@eml.cc changed:

   What|Removed |Added

 CC||bearophile_h...@eml.cc

--- Comment #1 from bearophile_h...@eml.cc ---
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. It's similar to the max/min
Python functions. And it's probably among my top additions to Phobos, beside a
pairwise (Issue 6788 ).

--


[Issue 13940] std.algorithm.argMin

2015-01-05 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=13940

--- Comment #2 from Peter Alexander  ---
(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).

--


[Issue 13940] std.algorithm.argMin

2015-01-05 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=13940

--- Comment #3 from bearophile_h...@eml.cc ---
(In reply to Peter Alexander from comment #2)

> 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).

Thank you for your answer (that should go also in Issue 4705 ). If you are
right, then:
- I want both functions for "min with key" and "max with key" (putting only one
of them in Phobos sucks);
- I prefer an unary function instead of a binary function. When you get used to
unary functions they are much more handy.

So I guess you can call call them keyMax and keyMin.

--


[Issue 13940] std.algorithm.argMin

2015-01-05 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=13940

--- Comment #4 from bearophile_h...@eml.cc ---
So its usage looks like:

someRange.keyMin!abs
someRange.keyMax!abs

--


[Issue 13940] std.algorithm.argMin

2015-01-06 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=13940

--- Comment #5 from bearophile_h...@eml.cc ---
See also the maxBy and minBy of F#:
http://msdn.microsoft.com/en-us/library/ee340421.aspx
http://msdn.microsoft.com/en-us/library/ee340252.aspx

--


[Issue 13940] std.algorithm.argMin

2016-03-06 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=13940

Nick Treleaven  changed:

   What|Removed |Added

   Keywords||pull
 CC||ntrel-...@mybtinternet.com

--- Comment #6 from Nick Treleaven  ---
https://github.com/D-Programming-Language/phobos/pull/4019

--


[Issue 13940] std.algorithm.argMin

2016-06-06 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=13940

greenify  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 CC||greeen...@gmail.com
 Resolution|--- |FIXED

--- Comment #7 from greenify  ---
Min and maxElement are part of Phobos since 2.071 - the crowd goes wild :) 
They support a custom mapping function and evaluation of the mapping is only
done once.

--