Skip to content

Instantly share code, notes, and snippets.

@deepakduggirala
Last active November 1, 2018 04:04
Show Gist options
  • Save deepakduggirala/3d6861be4b1ffb7eea08ec48a755c8e8 to your computer and use it in GitHub Desktop.
Save deepakduggirala/3d6861be4b1ffb7eea08ec48a755c8e8 to your computer and use it in GitHub Desktop.
Split a List into sublists, List to Tuple, lifting tuples
import qualified Data.List as L
splitEvery :: Int -> [a] -> [[a]]
splitEvery n [] = []
splitEvery n list = first : splitEvery n second
where (first, second) = L.splitAt n list
tuplify2 :: [a] -> (a, a)
tuplify2 [x, y] = (x, y)
tuplify2 _ = error "list does not have 2 elements"
liftFst :: (a -> c) -> (a, b) -> (c, b)
liftFst f (x, y) = (f x, y)
liftSnd :: (b -> c) -> (a, b) -> (a, c)
liftSnd f (x, y) = (x, f y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment