Created
July 22, 2011 16:19
-
-
Save forforf/1099771 to your computer and use it in GitHub Desktop.
Comprehension Patterns for Coffeescript
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
#map equivalent | |
x = for i in ['a', 'b', 'c'] | |
i + i | |
#=> ['aa', 'bb', 'cc'] | |
#for each equivalent | |
for i in ['a', 'b', 'c'] | |
#do side effect | |
null | |
#inject/collect equivalent example | |
for own key, val of [1, 2, 3, 4] | |
memo = (memo || 0) + val | |
#inject/collect equivalent general form | |
for own, key, val of someObjOrArray | |
memo = (memo || initVal) #set some intial value | |
memo = fn(memo, key, val) #operate on previous memo to get current memo | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment