-
-
Save cored/e8cc767e6a2faa0af0c918802757057a to your computer and use it in GitHub Desktop.
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
square = fn(x) -> x * x end | |
# calling an anonymous function uses a period | |
# before the parentheses | |
4 = square.(2) | |
# pattern matching the arguments can be used | |
first = fn([head|rest]) -> head end | |
1 = first.([1, 2]) | |
# anonymous functions are commonly used as arguments | |
# to other functions | |
[1, 4, 9] = Enum.map([1, 2, 3], square) | |
[3, 4, 5] = Enum.map([1, 2, 3], fn(x) -> x + 2 end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment