Proposal: add 'equating' function to Data.List

Greg Weber greg at gregweber.info
Fri Jul 18 20:28:29 UTC 2014


On Fri, Jul 18, 2014 at 1:07 PM, Henning Thielemann <
schlepptop at 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.html#v:groupBy1


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.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20140718/4fa41a26/attachment.html>


More information about the Libraries mailing list