Add example of anonymous function as argument

This commit is contained in:
Jay Hayes
2016-05-02 12:50:11 -05:00
parent a808d275db
commit 74b99676e7
2 changed files with 6 additions and 0 deletions

View File

@@ -72,6 +72,11 @@ defmodule Functions do
assert times_five_and_then(2, &square/1) == ___ assert times_five_and_then(2, &square/1) == ___
end end
koan "The '&' operation is not needed for anonymous functions" do
cube = fn number -> number * number * number end
assert times_five_and_then(2, cube) == ___
end
koan "Functions can be combined elegantly with the pipe operator" do koan "Functions can be combined elegantly with the pipe operator" do
result = "full-name" result = "full-name"
|> String.split("-") |> String.split("-")

View File

@@ -14,6 +14,7 @@ defmodule FunctionsTests do
6, 6,
6, 6,
100, 100,
1000,
"Full Name", "Full Name",
] ]