Created
February 6, 2009 03:12
-
-
Save djwonk/59199 to your computer and use it in GitHub Desktop.
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
-- splitWith even [0,1,3,5,0,0,7,7,0,0] >>> [[1,3,5], [7,7]] | |
splitWith :: (a -> Bool) -> [a] -> [[a]] | |
splitWith f list = splitWithIter f ansl [] list | |
splitWithIter :: (a -> Bool) -> ([[a]] -> a -> [[a]]) -> [[a]] -> [a] -> [[a]] | |
splitWithIter _ _ xs [] = xs | |
splitWithIter f o xs (l:ls) | |
| f l = splitWithIter f ansl xs ls | |
| otherwise = splitWithIter f atlsl (o xs l) ls | |
-- Append New Sub List (ansl) | |
-- For example: | |
-- ansl [[1,2]] 3 >>> [[1,2], 3] | |
ansl :: [[a]] -> a -> [[a]] | |
ansl xs y = xs ++ [[y]] | |
-- Append to Last Sub List (atlsl) | |
-- For example: | |
-- atlsl [[1,2]] 3 >>> [[1,2,3]] | |
atlsl :: [[a]] -> a -> [[a]] | |
atlsl xs y = init xs ++ [last xs ++ [y]] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment