Use triple underscore instead of double

This commit is contained in:
Uku Taht
2016-04-20 11:23:44 +01:00
parent ea2bb8f9bf
commit ded0f11ec6
16 changed files with 148 additions and 161 deletions

View File

@@ -6,20 +6,20 @@ defmodule Functions do
end
koan "Functions map arguments to outputs" do
assert greet("World") == __
assert greet("World") == ___
end
def multiply(a, b), do: a * b
koan "Single line functions are cool, but mind the command and the colon!" do
assert multiply(2, __) == 6
assert multiply(2, ___) == 6
end
def first(foo, bar), do: "#{foo} and #{bar}"
def first(foo), do: "Only #{foo}"
koan "Functions with the same name are distinguished by the number of arguments they take" do
assert first("One", "Two") == __
assert first("One") == __
assert first("One", "Two") == ___
assert first("One") == ___
end
def repeat_again(message, times \\ 5) do
@@ -27,49 +27,49 @@ defmodule Functions do
end
koan "Not all arguments are always needed" do
assert repeat_again("Hello ") == __
assert repeat_again("Hello ", 2) == __
assert repeat_again("Hello ") == ___
assert repeat_again("Hello ", 2) == ___
end
def sum_up(thing) when is_list(thing), do: :entire_list
def sum_up(_thing), do: :single_thing
koan "Functions can be picky and apply to only certain types" do
assert sum_up([1,2,3]) == __
assert sum_up(1) == __
assert sum_up([1,2,3]) == ___
assert sum_up(1) == ___
end
def bigger(a,b) when a > b, do: "#{a} is bigger than #{b}"
def bigger(a,b) when a <= b, do: "#{a} is not bigger than #{b}"
koan "Intricate guards are possible, but be mindful of the reader" do
assert bigger(10, 5) == __
assert bigger(4, 27) == __
assert bigger(10, 5) == ___
assert bigger(4, 27) == ___
end
def the_length(0), do: "It was zero"
def the_length(number), do: "The length was #{number}"
koan "For those individual one-offs, you can even guard on the arguments themselves" do
assert the_length(0) == __
assert the_length(5) == __
assert the_length(0) == ___
assert the_length(5) == ___
end
koan "Little anonymous functions are common, and called with a dot" do
multiply = fn (a,b) -> a * b end
assert multiply.(2,3) == __
assert multiply.(2,3) == ___
end
koan "You can even go shorter, by using &(..) and positional arguments" do
multiply = &(&1 * &2)
assert multiply.(2,3) == __
assert multiply.(2,3) == ___
end
def times_five_and_then(number, fun), do: fun.(number*5)
def square(number), do: number * number
koan "You can pass functions around as arguments. Place and '&' before the name and state the arity" do
assert times_five_and_then(2, &square/1) == __
assert times_five_and_then(2, &square/1) == ___
end
koan "Functions can be combined elegantly with the pipe operator" do
@@ -78,6 +78,6 @@ defmodule Functions do
|> Enum.map(&(String.capitalize(&1)))
|> Enum.join(" ")
assert result == __
assert result == ___
end
end