Last active
November 1, 2018 04:04
-
-
Save deepakduggirala/3d6861be4b1ffb7eea08ec48a755c8e8 to your computer and use it in GitHub Desktop.
Split a List into sublists, List to Tuple, lifting tuples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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