Created
December 1, 2012 19:13
-
-
Save jdewind/4184216 to your computer and use it in GitHub Desktop.
Fun inline list comprehension in Haskell
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
[x | x <- (zip [1..] ['A'..'Z']), even (fst x)] |
Tightened up ruby version:
xs = ('A'..'Z'); (1..xs.count).zip(xs).select { |i,x| i.even? }
Alternative approach:
('A'..'Z').each_with_index.map { |x,i| [i+1,x] if (i+1).even? }.compact
Neither is quite as elegant as the Haskell, of course.
Thanks John!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In ruby: