Added pattern matching koan for keyword list
This commit is contained in:
@@ -45,6 +45,12 @@ defmodule PatternMatching do
|
||||
end
|
||||
end
|
||||
|
||||
koan "So does the keyword lists" do
|
||||
kw_list = [type: "car", year: 2016, make: "Honda"]
|
||||
[_type | [_year | [tuple]]] = kw_list
|
||||
assert tuple == {___, ___}
|
||||
end
|
||||
|
||||
koan "The pattern can make assertions about what it expects" do
|
||||
assert match?([1, _second, _third], ___)
|
||||
end
|
||||
|
@@ -11,6 +11,7 @@ defmodule PatternsTests do
|
||||
"eggs, milk",
|
||||
"Honda",
|
||||
MatchError,
|
||||
{:multiple, [:make, "Honda"]},
|
||||
[1,2,3],
|
||||
{:multiple, ["Meow", "Woof", "Eh?"]},
|
||||
{:multiple, ["Mickey", "Donald", "I need a name!"]},
|
||||
|
Reference in New Issue
Block a user