On 9/14/11 5:57 PM, bearophile wrote:
I'd like to receive some comments from Andrei about one of the most
nagging problems I have with std.algorithm, it's not a big issue, but
I bump my nose against it few times every week:
http://d.puremagic.com/issues/show_bug.cgi?id=4705
If you have questions or doubts, feel free to ask here or in
Bugzilla.
Bye, bearophile
So you propose adding these (among others):
min(collection)
min!(callable)(collection)
max(collection)
max!(callable)(collection)
We now have:
min(a, b, c, ...)
max(a, b, c, ...)
minCount!callable(range)
minPos!callable(range)
The latter two take a binary predicate that customizes the comparison
function. That's why maxCount and maxPos are not provided.
This is where things get a bit problematic. In the calls min!foo(range)
and minCount!foo(range), the function foo has a completely different
meaning - the first is a unary mapper, the second is a binary predicate.
This is quite confusing.
I had the suspicion minCount and minPos where poor choices of name, but
I was unable to find a better name for "min" there. It's something like
"extremum" or "bound". Finding a good name would be great.
I'm not sure how to solve this in a way that will minimize code
breakage. One possibility I can think of is to define and use
isUnaryFunction and isBinaryFunction.
However, one-argument calls such as min(collection) seem unambiguous and
valuable to me.
Second, you propose
mins(collection)
mins!(callable)(collection)
maxs(collection)
maxs!(callable)(collection)
that return all elements. I'm not sure how you plan to return - create a
new array, or iterate a la filter? The latter is interesting, but for
either variant is quite difficult to find use examples that are frequent
enough to make min followed by filter too verbose.
Thanks,
Andrei