Merge pull request #199 from codefupanda/master
Fetching values of repeated key in keywordlist
This commit is contained in:
@@ -15,11 +15,11 @@ defmodule KeywordLists do
|
|||||||
assert kw_list[:foo] == ___
|
assert kw_list[:foo] == ___
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "You could access a second key by removing the first" do
|
koan "You could access the values of repeating key" do
|
||||||
kw_list = [foo: "bar", foo: "baz"]
|
kw_list = [foo: "bar", foo1: "bar1", foo: "baz"]
|
||||||
[_|kw_list] = kw_list
|
values = Keyword.get_values(kw_list, :foo)
|
||||||
|
|
||||||
assert kw_list[:foo] == ___
|
assert List.last(values) == ___
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "Keyword lists are just special syntax for lists of two-element tuples" do
|
koan "Keyword lists are just special syntax for lists of two-element tuples" do
|
||||||
|
@@ -45,6 +45,12 @@ defmodule PatternMatching do
|
|||||||
end
|
end
|
||||||
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
|
koan "The pattern can make assertions about what it expects" do
|
||||||
assert match?([1, _second, _third], ___)
|
assert match?([1, _second, _third], ___)
|
||||||
end
|
end
|
||||||
|
@@ -11,6 +11,7 @@ defmodule PatternsTests do
|
|||||||
"eggs, milk",
|
"eggs, milk",
|
||||||
"Honda",
|
"Honda",
|
||||||
MatchError,
|
MatchError,
|
||||||
|
{:multiple, [:make, "Honda"]},
|
||||||
[1,2,3],
|
[1,2,3],
|
||||||
{:multiple, ["Meow", "Woof", "Eh?"]},
|
{:multiple, ["Meow", "Woof", "Eh?"]},
|
||||||
{:multiple, ["Mickey", "Donald", "I need a name!"]},
|
{:multiple, ["Mickey", "Donald", "I need a name!"]},
|
||||||
|
Reference in New Issue
Block a user