Proposal: Add functions to get consecutive elements to Data.List

Johan Holmquist holmisen at gmail.com
Wed Apr 13 09:48:10 UTC 2016


It is not strictly more general because it cannot handle empty sequences.

2016-04-13 10:47 GMT+02:00 Henning Thielemann <lemming at henning-thielemann.de
>:

>
> On Wed, 13 Apr 2016, David Feuer wrote:
>
> -1. I think these are good functions, but I don't think base is the place
>> for them. They just don't seem "fundamental"
>> enough. That said, they can be optimized for list fusion based on this
>> implementation, and even use build to fuse the
>> other way. No zipWith implementation will do this.
>>
>> zipWithAdj f xs = foldr go (`seq` []) xs Nothing where
>>   go x r Nothing = r (Just x)
>>   go x r (Just prev) = f prev x : r (Just x)
>>
>
>
> Btw. I have also this more general variant:
>
> mapAdjacent :: (Traversable f) => (a -> a -> b) -> NonEmpty f a -> f b
> mapAdjacent f (NonEmpty x xs) =
>    snd $ Trav.mapAccumL (\a0 a1 -> (a1, f a0 a1)) x xs
>
>
> Maybe this is also better for fusion?
>
>
>
> http://hackage.haskell.org/package/non-empty-0.2.1/docs/Data-NonEmpty.html#v:mapAdjacent
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20160413/5505122f/attachment.html>


More information about the Libraries mailing list