
On Fri, Jul 18, 2014 at 1:07 PM, Henning Thielemann < schlepptop@henning-thielemann.de> wrote:
Am 18.07.2014 21:57, schrieb Greg Weber:
I think the `By` functions that expect a Bool are all cumbersome because
they are too flexible. 100% of the time I personally use these functions I want to use Ord or Eq. What I would like to see is a function groupOn next to groupBy.
groupOn :: Eq b => (a -> b) -> [a] -> [[a]]
Then equating is no longer needed, and one just writes: groupOn snd I believe this style also gives better opportunity for optimization (Scwartzian transform).
It's also in my utility package:
http://hackage.haskell.org/package/utility-ht-0.0.10/ docs/Data-List-Key.html
I have also a version of 'groupBy' that returns a list of non-empty lists:
http://hackage.haskell.org/package/non-empty-0.2/docs/ Data-NonEmpty-Mixed.html#v:groupBy
non-empty looks nice! semigroups has groupBy1 now that returns NonEmpty http://hackage.haskell.org/package/semigroups-0.15.1/docs/Data-List-NonEmpty... It's all Haskell 98.
You should add mono-traversable (Data.MinLen) [1] to your compariisons. It should be a lot more efficient when tracking length beyond 1 element, but it is definitely not Haskell 98. [1] http://hackage.haskell.org/package/mono-traversable-0.6.0.4/docs/Data-MinLen...