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

Frerich Raabe raabe at froglogic.com
Wed Apr 13 08:23:46 UTC 2016


On 2016-04-12 22:55, Johan Holmquist wrote:
> I propose adding two new functions to Data.List:
> 
>     zipConsecutives :: [a] -> [(a,a)]
>     zipConsecutives xs = zip xs (tail xs)
> 
>     zipConsecutivesWith :: (a -> a -> b) -> [a] -> [b]
>     zipConsecutivesWith f xs = zipWith f xs (tail xs)
> 
> (with possibly more efficient implementations)

For what it's worth, the function for combining adjacent elements is 
sometimes called 'pairwise' in Python, maybe based on this list of recipes:

   https://docs.python.org/2/library/itertools.html#recipes

Maybe that's a viable naming alternative?

-- 
Frerich Raabe - raabe at froglogic.com
www.froglogic.com - Multi-Platform GUI Testing


More information about the Libraries mailing list