Skip to content

Instantly share code, notes, and snippets.

@rangalo
Created January 20, 2010 16:31
Show Gist options
  • Save rangalo/281977 to your computer and use it in GitHub Desktop.
Save rangalo/281977 to your computer and use it in GitHub Desktop.
-- file: ch04/Fold.hs
myFilter :: (a -> Bool) -> [a] -> [a]
myFilter p xs = foldr step [] xs
where step x ys | p x = x : ys
| otherwise = ys
myFoldl :: (a -> b -> a) -> a -> [b] -> a
myFoldl f z xs = foldr step id xs z
where step x g a = g (f a x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment