On 10/15/12 7:39 PM, Mehrdad wrote:
On Monday, 15 October 2012 at 22:35:41 UTC, Andrei Alexandrescu wrote:
On 10/15/12 5:35 PM, Mehrdad wrote:
I think we need something like these in Phobos -- I was quite surprised
that I didn't find these in Phobos. They're really handy in Python.
[snip]
Ideas?
Yes, I wanted to add some relational operators forever! There's a
group() function in std.algorithm but doesn't offer a range of ranges.
Andrei
+1 yeah, group() was useless for me. I wanted to group consecutive items
together by some criterion, which it (ironically) explicitly doesn't do.
It's not ironic, it's intentional. In libraries such as Scala's you
specify GroupBy with whatever predicate against an arbitrary stream, and
it takes care of all the intermediate data structures (e.g. hashes,
arrays) and/or additional operations (sorting).
In D, there's a strong emphasis of explicit costs and benefits, so to
group by an arbitrary key you'd first sort by that key and then use the
"dumb group" that only knows how to group on adjacent entries.
I'm not sure which approach is best, but I tend to think the current
approach is a better fit for D's general ethos.
Andrei