Skip to content

Instantly share code, notes, and snippets.

@weidagang
Created November 18, 2014 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weidagang/1f03d0cedfe9e0db9ae8 to your computer and use it in GitHub Desktop.
Save weidagang/1f03d0cedfe9e0db9ae8 to your computer and use it in GitHub Desktop.
mapreduce.hs
reduce :: (a -> b -> b) -> b -> [a] -> b
reduce f b [] = b
reduce f b (x:xs) = f x (reduce f b xs)
map :: (a -> b) -> [a] -> [b]
map f = reduce (\a b -> (f a) : b) []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment