Last active
January 18, 2016 14:43
-
-
Save merijn/c163cc106fd245d1cf2e to your computer and use it in GitHub Desktop.
Efficient split in half
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
splitInHalf :: [a] -> ([a], [a]) | |
splitInHalf [] = ([], []) | |
splitInHalf xs = go id xs xs | |
where | |
go :: ([b] -> [b]) -> [b] -> [b] -> ([b], [b]) | |
go f xs [] = (f [], xs) | |
go f xs [_] = (f [], xs) | |
go f (x:xs) (_:_:ys) = go (f . (x:)) xs ys |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment