I was wondering if there would be a concise/one-liner way to do the following:
pack :: [a] -> [(a, a)] pack [] = [] pack [_] = [] pack (x:y:xs) = (
We can easily split the list into two lists with alternating elements with this tidbit (due to HaskellWiki)
foldr (\a ~(x,y) -> (a:y,x)) ([],[])
All that remains is to combine the lists with zip
zip
pack :: [a] -> [(a, a)] pack = uncurry zip . foldr (\a ~(x,y) -> (a:y,x)) ([],[])