Skip to content

Instantly share code, notes, and snippets.

@trobertson
Created November 20, 2012 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save trobertson/4121140 to your computer and use it in GitHub Desktop.
Save trobertson/4121140 to your computer and use it in GitHub Desktop.
-- adds up how many zeros are in the elements of a list
cz :: Show a => [a] -> Int
cz = sum . map length . map (filter (=='0')) . map show
-- the (.) means function composition, and lets you exclude the
-- variable being operated on. so:
-- f . g == f (g (x))
cz' :: Show a => [a] -> Int
cz' s = sum (map length (map (filter (=='0')) (map show s)))
-- to make it more readable:
cz'' :: Show a => [a] -> Int
cz'' s = sum c
where c = map length b
b = map (filter (=='0')) a
a = map show s
@syntacticsugar
Copy link

GNARLY!!!!!!!!!!!!!!!!

@syntacticsugar
Copy link

wut.... is this ur 0nly g1st????

i iz d1sapp01nt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment