Created
April 24, 2015 02:01
-
-
Save kevinadi/b32da7b1054ca93b6d89 to your computer and use it in GitHub Desktop.
Haskell: split a string to chunks
This file contains hidden or 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
chunks :: Int -> [a] -> [[a]] | |
chunks _ [] = [] | |
chunks n xs = (fst c) : chunks n (snd c) | |
where c = splitAt n xs | |
chunks' :: Int -> [a] -> [[a]] | |
chunks' n = unfoldr (\b -> if null b then Nothing else Just (splitAt n b)) | |
chunks'' :: Int -> [a] -> [[a]] | |
chunks'' n = takeWhile (not.null) . unfoldr (Just . splitAt n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment