First commit
This commit is contained in:
commit
1dba0af064
36 changed files with 1065 additions and 0 deletions
28
chapter4/todo_map_entry.ex
Normal file
28
chapter4/todo_map_entry.ex
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
defmodule MultiDict do
|
||||
def new(), do: %{}
|
||||
|
||||
def add(dict, key, value) do
|
||||
Map.update(
|
||||
dict,
|
||||
key,
|
||||
[value],
|
||||
&[value | &1]
|
||||
)
|
||||
end
|
||||
|
||||
def get(dict, key) do
|
||||
Map.get(dict, key, [])
|
||||
end
|
||||
end
|
||||
|
||||
defmodule TodoList do
|
||||
def new(), do: MultiDict.new()
|
||||
|
||||
def add_entry(todo_list, entry) do
|
||||
MultiDict.add(todo_list, entry.date, entry)
|
||||
end
|
||||
|
||||
def entries(todo_list, date) do
|
||||
MultiDict.get(todo_list, date)
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue