On Wednesday, 20 January 2016 at 17:29:28 UTC, H. S. Teoh wrote:
On Wed, Jan 20, 2016 at 12:16:00PM -0500, Andrei Alexandrescu
via Digitalmars-d wrote:
This is one of those cases in which we were pedantically right
to not add them, but their equivalents look like crap.
I don't like this. I'd much rather we rename those functions
to be something more generic. After all, minPos is a horrible
name when the predicate has nothing to do with minimum values.
What about extremumPos? (Though that's rather ugly to type.)
maxCount sounds too much like it's suppose to be a function in
SQL querying, and minCount... ugg... now I wonder what in the
world we're talking about.
From algorithm.d:
int[] a = [ 2, 3, 4, 1, 2, 4, 1, 1, 2 ];
// Minimum is 1 and occurs 3 times
assert(a.minCount == tuple(1, 3));
// Maximum is 4 and occurs 2 times
assert(a.maxCount == tuple(4, 2));
// Minimum is 1 and first occurs in position 3
assert(a.minPos == [ 1, 2, 4, 1, 1, 2 ]);
// Maximum is 4 and first occurs in position 2
assert(a.maxPos == [ 4, 1, 2, 4, 1, 1, 2 ]);
These unittests make it completely clear what it wants to do. I'd
almost say lowestCount and highestCount would almost be better,
but i am not sure. or just unitCount? Or countOf and posOf? which
make a lot more sense when instantiated: So a.countOf!("a < b")?
I'm seriously behind on all of this.