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] == ___
|
||||
end
|
||||
|
||||
koan "You could access a second key by removing the first" do
|
||||
kw_list = [foo: "bar", foo: "baz"]
|
||||
[_|kw_list] = kw_list
|
||||
koan "You could access the values of repeating key" do
|
||||
kw_list = [foo: "bar", foo1: "bar1", foo: "baz"]
|
||||
values = Keyword.get_values(kw_list, :foo)
|
||||
|
||||
assert kw_list[:foo] == ___
|
||||
assert List.last(values) == ___
|
||||
end
|
||||
|
||||
koan "Keyword lists are just special syntax for lists of two-element tuples" do
|
||||
|
@@ -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