From ca1bd3632262a104d620613ec06facec0eee5fdb Mon Sep 17 00:00:00 2001 From: fabien townsend Date: Sun, 24 Apr 2016 10:18:57 +0200 Subject: [PATCH] Modify lists and maps style --- lib/koans/05_maps.ex | 6 +++--- lib/koans/06_structs.ex | 4 ++-- lib/koans/07_pattern_matching.ex | 6 +++--- lib/koans/08_functions.ex | 2 +- lib/koans/09_enums.ex | 34 ++++++++++++++++---------------- lib/koans/11_tasks.ex | 2 +- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/lib/koans/05_maps.ex b/lib/koans/05_maps.ex index 77c02f2..6f59a33 100644 --- a/lib/koans/05_maps.ex +++ b/lib/koans/05_maps.ex @@ -37,7 +37,7 @@ defmodule Maps do end koan "Or you can use some syntactic sugar for existing elements" do - younger_person = %{ @person | age: 16 } + younger_person = %{@person | age: 16} assert Map.fetch(younger_person, :age) == ___ end @@ -51,12 +51,12 @@ defmodule Maps do end koan "When merging, the last map wins" do - merged = Map.merge(@person, %{ last_name: "Baratheon"}) + merged = Map.merge(@person, %{last_name: "Baratheon"}) assert Map.fetch(merged, :last_name) == ___ end koan "You can also select sub-maps out of a larger map" do - initial = %{ name: "Jon", last_name: "Snow", age: 15} + initial = %{name: "Jon", last_name: "Snow", age: 15} assert Map.take(initial, [:name, :last_name]) == ___ end end diff --git a/lib/koans/06_structs.ex b/lib/koans/06_structs.ex index a7442f6..32a6764 100644 --- a/lib/koans/06_structs.ex +++ b/lib/koans/06_structs.ex @@ -2,7 +2,7 @@ defmodule Structs do use Koans defmodule Person do - defstruct [:name, :age ] + defstruct [:name, :age] end koan "Structs are defined and named after a module" do @@ -22,7 +22,7 @@ defmodule Structs do koan "Update fields with the pipe '|' operator" do joe = %Person{name: "Joe", age: 23} - older = %{ joe | age: joe.age + 10} + older = %{joe | age: joe.age + 10} assert older.age == ___ end diff --git a/lib/koans/07_pattern_matching.ex b/lib/koans/07_pattern_matching.ex index 9156bd7..377e4c8 100644 --- a/lib/koans/07_pattern_matching.ex +++ b/lib/koans/07_pattern_matching.ex @@ -16,7 +16,7 @@ defmodule PatternMatching do end koan "Patterns can be used to pull things apart" do - [head | tail] = [1,2,3,4] + [head | tail] = [1, 2, 3, 4] assert head == ___ assert tail == ___ @@ -24,13 +24,13 @@ defmodule PatternMatching do koan "And then put them back together" do head = 1 - tail = [2,3,4] + tail = [2, 3, 4] assert ___ == [head | tail] end koan "Some values can be ignored" do - [_first, _second, third, _fourth] = [1,2,3,4] + [_first, _second, third, _fourth] = [1, 2, 3, 4] assert third == ___ end diff --git a/lib/koans/08_functions.ex b/lib/koans/08_functions.ex index 8631ba4..00f0976 100644 --- a/lib/koans/08_functions.ex +++ b/lib/koans/08_functions.ex @@ -35,7 +35,7 @@ defmodule Functions do def sum_up(_thing), do: :single_thing koan "Functions can be picky and apply only to certain types" do - assert sum_up([1,2,3]) == ___ + assert sum_up([1 ,2 ,3]) == ___ assert sum_up(1) == ___ end diff --git a/lib/koans/09_enums.ex b/lib/koans/09_enums.ex index 565ac3e..474dd46 100644 --- a/lib/koans/09_enums.ex +++ b/lib/koans/09_enums.ex @@ -2,7 +2,7 @@ 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 @@ -11,69 +11,69 @@ defmodule Enums do 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?([6,7,8,9], &less_than_five?/1) == ___ + assert Enum.all?([1 ,2 ,3], &less_than_five?/1) == ___ + assert Enum.all?([6 ,7 ,8 ,9], &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 - input = [1,2,3] + input = [1 ,2 ,3] assert Enum.member?(input, 1) == ___ assert Enum.member?(input, 30) == ___ end 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], &even?/1) == ___ + assert Enum.find([1 ,2 ,3], &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 diff --git a/lib/koans/11_tasks.ex b/lib/koans/11_tasks.ex index d28744c..94376b3 100644 --- a/lib/koans/11_tasks.ex +++ b/lib/koans/11_tasks.ex @@ -37,7 +37,7 @@ defmodule Tasks do end koan "You can yield to multiple tasks at once and extract the results" do - squares = [1,2,3,4] + squares = [1 ,2 ,3 ,4] |> Enum.map(fn(number) -> Task.async(fn -> number * number end) end) |> Task.yield_many(100) |> Enum.map(fn({_task,{:ok, result}}) -> result end)