Created
August 19, 2015 21:35
-
-
Save JoshCheek/422ca40091f1995ddcc3 to your computer and use it in GitHub Desktop.
All the syntaxes I can think of offhand for lambdas / blocks
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
# ----- Lambda ----- | |
# the syntax for a lambda: stabby arrow | |
-> a { a + a } | |
# ----- Block ----- | |
# the two literal syntaxes for a block, + syntax to place lambda into block slot | |
lambda { |a| a + a } | |
lambda do |a| a + a end | |
lambda &->(a) { a + a } | |
# ----- Parens are optional ----- | |
->(a) { a + a } | |
lambda() { |a| a + a } | |
lambda() do |a| | |
a + a | |
end | |
l = ->(a) { a + a } | |
lambda(&l) | |
# ----- Lambda with both block literal syntaxes ----- | |
-> a { a + a } | |
-> a do | |
a + a | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment