Skip to content

Commit

Permalink
Merge pull request #111 from joneslee85/patch-1
Browse files Browse the repository at this point in the history
Refactor the comma in List syntax
  • Loading branch information
ukutaht committed May 5, 2016
2 parents 964d5fe + c1e3f6a commit 0a57e38
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions lib/koans/09_enums.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ defmodule Enums do
use Koans

koan "Knowing how many elements are in a list is important for book-keeping" do
assert Enum.count([1 ,2 ,3]) == ___
assert Enum.count([1, 2, 3]) == ___
end

koan "Depending on the type, it counts pairs" do
assert Enum.count(%{ a: :foo, b: :bar}) == ___
assert Enum.count(%{a: :foo, b: :bar}) == ___
end

def less_than_five?(n), do: n < 5
koan "Elements can have a lot in common" do
assert Enum.all?([1 ,2 ,3], &less_than_five?/1) == ___
assert Enum.all?([4, 6 ,8], &less_than_five?/1) == ___
assert Enum.all?([1, 2, 3], &less_than_five?/1) == ___
assert Enum.all?([4, 6, 8], &less_than_five?/1) == ___
end

def even?(n), do: rem(n, 2) == 0
koan "Sometimes you just want to know if there are any elements fulfilling a condition" do
assert Enum.any?([1 ,2 ,3], &even?/1) == ___
assert Enum.any?([1 ,3 ,5], &even?/1) == ___
assert Enum.any?([1, 2, 3], &even?/1) == ___
assert Enum.any?([1, 3, 5], &even?/1) == ___
end

koan "Sometimes you just want to know if an element is part of the party" do
Expand All @@ -29,51 +29,51 @@ defmodule Enums do

def multiply_by_ten(n), do: 10 * n
koan "Map converts each element of a list by running some function with it" do
assert Enum.map([1 ,2 ,3], &multiply_by_ten/1) == ___
assert Enum.map([1, 2, 3], &multiply_by_ten/1) == ___
end

def odd?(n), do: rem(n, 2) == 1

koan "Filter allows you to only keep what you really care about" do
assert Enum.filter([1 ,2 ,3], &odd?/1) == ___
assert Enum.filter([1, 2, 3], &odd?/1) == ___
end

koan "Reject will help you throw out unwanted cruft" do
assert Enum.reject([1 ,2 ,3], &odd?/1) == ___
assert Enum.reject([1, 2, 3], &odd?/1) == ___
end

koan "You three there, follow me!" do
assert Enum.take([1 ,2 ,3 ,4 ,5], 3) == ___
assert Enum.take([1, 2, 3, 4, 5], 3) == ___
end

koan "You can ask for a lot, but Enum won't hand you more than you give" do
assert Enum.take([1 ,2 ,3 ,4 ,5], 10) == ___
assert Enum.take([1, 2, 3, 4, 5], 10) == ___
end

koan "Just like taking, you can also drop elements" do
assert Enum.drop([-1 ,0 ,1 ,2 ,3], 2) == ___
assert Enum.drop([-1, 0, 1, 2, 3], 2) == ___
end

koan "Zip-up in pairs!" do
numbers = [1 ,2 ,3]
numbers = [1, 2, 3]
letters = [:a, :b, :c]
assert Enum.zip(numbers, letters) == ___
end

koan "When you want to find that one pesky element" do
assert Enum.find([1 ,2 ,3, 4], &even?/1) == ___
assert Enum.find([1, 2, 3, 4], &even?/1) == ___
end

def divisible_by_five?(n), do: rem(n, 5) == 0
koan "...but you don't quite find it..." do
assert Enum.find([1 ,2 ,3], &divisible_by_five?/1) == ___
assert Enum.find([1, 2, 3], &divisible_by_five?/1) == ___
end

koan "...you can settle for a consolation prize" do
assert Enum.find([1 ,2 ,3], :no_such_element, &divisible_by_five?/1) == ___
assert Enum.find([1, 2, 3], :no_such_element, &divisible_by_five?/1) == ___
end

koan "Collapse an entire list of elements down to a single one by repeating a function." do
assert Enum.reduce([1 ,2 ,3], 0, fn(element, accumulator) -> element + accumulator end) == ___
assert Enum.reduce([1, 2, 3], 0, fn(element, accumulator) -> element + accumulator end) == ___
end
end

0 comments on commit 0a57e38

Please sign in to comment.