Skip to content
Permalink
Browse files
replace hashdict with maps
  • Loading branch information
sasa1977 committed Jan 5, 2016
1 parent 061dd60 commit 51bc04bf48730bfbb6141ad781f8300cc6e91db5
Show file tree
Hide file tree
Showing 48 changed files with 242 additions and 242 deletions.
@@ -1,8 +1,8 @@
defmodule TodoList do
def new, do: HashDict.new
def new, do: %{}

def add_entry(todo_list, date, title) do
HashDict.update(
Map.update(
todo_list,
date,
[title],
@@ -11,6 +11,6 @@ defmodule TodoList do
end

def entries(todo_list, date) do
HashDict.get(todo_list, date, [])
Map.get(todo_list, date, [])
end
end
end
@@ -1,5 +1,5 @@
defmodule TodoList do
defstruct auto_id: 1, entries: HashDict.new
defstruct auto_id: 1, entries: %{}

def new(entries \\ []) do
Enum.reduce(
@@ -14,7 +14,7 @@ defmodule TodoList do
entry
) do
entry = Map.put(entry, :id, auto_id)
new_entries = HashDict.put(entries, auto_id, entry)
new_entries = Map.put(entries, auto_id, entry)

%TodoList{todo_list |
entries: new_entries,
@@ -48,7 +48,7 @@ defmodule TodoList do

old_entry ->
new_entry = updater_fun.(old_entry)
new_entries = HashDict.put(entries, new_entry.id, new_entry)
new_entries = Map.put(entries, new_entry.id, new_entry)
%TodoList{todo_list | entries: new_entries}
end
end
@@ -58,6 +58,6 @@ defmodule TodoList do
%TodoList{entries: entries} = todo_list,
entry_id
) do
%TodoList{todo_list | entries: HashDict.delete(entries, entry_id)}
%TodoList{todo_list | entries: Map.delete(entries, entry_id)}
end
end
end
@@ -1,5 +1,5 @@
defmodule TodoList do
defstruct auto_id: 1, entries: HashDict.new
defstruct auto_id: 1, entries: %{}

def new, do: %TodoList{}

@@ -8,7 +8,7 @@ defmodule TodoList do
entry
) do
entry = Map.put(entry, :id, auto_id)
new_entries = HashDict.put(entries, auto_id, entry)
new_entries = Map.put(entries, auto_id, entry)

%TodoList{todo_list |
entries: new_entries,
@@ -42,7 +42,7 @@ defmodule TodoList do

old_entry ->
new_entry = updater_fun.(old_entry)
new_entries = HashDict.put(entries, new_entry.id, new_entry)
new_entries = Map.put(entries, new_entry.id, new_entry)
%TodoList{todo_list | entries: new_entries}
end
end
@@ -52,6 +52,6 @@ defmodule TodoList do
%TodoList{entries: entries} = todo_list,
entry_id
) do
%TodoList{todo_list | entries: HashDict.delete(entries, entry_id)}
%TodoList{todo_list | entries: Map.delete(entries, entry_id)}
end
end
end
@@ -1,8 +1,8 @@
defmodule MultiDict do
def new, do: HashDict.new
def new, do: %{}

def add(dict, key, value) do
HashDict.update(
Map.update(
dict,
key,
[value],
@@ -11,7 +11,7 @@ defmodule MultiDict do
end

def get(dict, key) do
HashDict.get(dict, key, [])
Map.get(dict, key, [])
end
end

@@ -25,4 +25,4 @@ defmodule TodoList do
def entries(todo_list, date) do
MultiDict.get(todo_list, date)
end
end
end
@@ -1,5 +1,5 @@
defmodule TodoList do
defstruct auto_id: 1, entries: HashDict.new
defstruct auto_id: 1, entries: %{}

def new(entries \\ []) do
Enum.reduce(
@@ -14,7 +14,7 @@ defmodule TodoList do
entry
) do
entry = Map.put(entry, :id, auto_id)
new_entries = HashDict.put(entries, auto_id, entry)
new_entries = Map.put(entries, auto_id, entry)

%TodoList{todo_list |
entries: new_entries,
@@ -48,7 +48,7 @@ defmodule TodoList do

old_entry ->
new_entry = updater_fun.(old_entry)
new_entries = HashDict.put(entries, new_entry.id, new_entry)
new_entries = Map.put(entries, new_entry.id, new_entry)
%TodoList{todo_list | entries: new_entries}
end
end
@@ -58,7 +58,7 @@ defmodule TodoList do
%TodoList{entries: entries} = todo_list,
entry_id
) do
%TodoList{todo_list | entries: HashDict.delete(entries, entry_id)}
%TodoList{todo_list | entries: Map.delete(entries, entry_id)}
end
end

@@ -103,4 +103,4 @@ defmodule TodoList.CsvImporter do
defp create_entry({date, title}) do
%{date: date, title: title}
end
end
end
@@ -1,8 +1,8 @@
defmodule MultiDict do
def new, do: HashDict.new
def new, do: %{}

def add(dict, key, value) do
HashDict.update(
Map.update(
dict,
key,
[value],
@@ -11,7 +11,7 @@ defmodule MultiDict do
end

def get(dict, key) do
HashDict.get(dict, key, [])
Map.get(dict, key, [])
end
end

@@ -25,4 +25,4 @@ defmodule TodoList do
def entries(todo_list, date) do
MultiDict.get(todo_list, date)
end
end
end
@@ -46,7 +46,7 @@ end


defmodule TodoList do
defstruct auto_id: 1, entries: HashDict.new
defstruct auto_id: 1, entries: %{}

def new(entries \\ []) do
Enum.reduce(
@@ -61,7 +61,7 @@ defmodule TodoList do
entry
) do
entry = Map.put(entry, :id, auto_id)
new_entries = HashDict.put(entries, auto_id, entry)
new_entries = Map.put(entries, auto_id, entry)

%TodoList{todo_list |
entries: new_entries,
@@ -95,7 +95,7 @@ defmodule TodoList do

old_entry ->
new_entry = updater_fun.(old_entry)
new_entries = HashDict.put(entries, new_entry.id, new_entry)
new_entries = Map.put(entries, new_entry.id, new_entry)
%TodoList{todo_list | entries: new_entries}
end
end
@@ -105,6 +105,6 @@ defmodule TodoList do
%TodoList{entries: entries} = todo_list,
entry_id
) do
%TodoList{todo_list | entries: HashDict.delete(entries, entry_id)}
%TodoList{todo_list | entries: Map.delete(entries, entry_id)}
end
end
end
@@ -43,7 +43,7 @@ end


defmodule TodoList do
defstruct auto_id: 1, entries: HashDict.new
defstruct auto_id: 1, entries: %{}

def new(entries \\ []) do
Enum.reduce(
@@ -58,7 +58,7 @@ defmodule TodoList do
entry
) do
entry = Map.put(entry, :id, auto_id)
new_entries = HashDict.put(entries, auto_id, entry)
new_entries = Map.put(entries, auto_id, entry)

%TodoList{todo_list |
entries: new_entries,
@@ -92,7 +92,7 @@ defmodule TodoList do

old_entry ->
new_entry = updater_fun.(old_entry)
new_entries = HashDict.put(entries, new_entry.id, new_entry)
new_entries = Map.put(entries, new_entry.id, new_entry)
%TodoList{todo_list | entries: new_entries}
end
end
@@ -102,6 +102,6 @@ defmodule TodoList do
%TodoList{entries: entries} = todo_list,
entry_id
) do
%TodoList{todo_list | entries: HashDict.delete(entries, entry_id)}
%TodoList{todo_list | entries: Map.delete(entries, entry_id)}
end
end
end
@@ -14,14 +14,14 @@ defmodule KeyValueStore do
end

def init(_) do
{:ok, HashDict.new}
{:ok, %{}}
end

def handle_cast({:put, key, value}, state) do
{:noreply, HashDict.put(state, key, value)}
{:noreply, Map.put(state, key, value)}
end

def handle_call({:get, key}, _, state) do
{:reply, HashDict.get(state, key), state}
{:reply, Map.get(state, key), state}
end
end
end
@@ -44,14 +44,14 @@ defmodule KeyValueStore do
end

def init do
HashDict.new
%{}
end

def handle_call({:put, key, value}, state) do
{:ok, HashDict.put(state, key, value)}
{:ok, Map.put(state, key, value)}
end

def handle_call({:get, key}, state) do
{HashDict.get(state, key), state}
{Map.get(state, key), state}
end
end
end
@@ -56,14 +56,14 @@ defmodule KeyValueStore do
end

def init do
HashDict.new
%{}
end

def handle_cast({:put, key, value}, state) do
HashDict.put(state, key, value)
Map.put(state, key, value)
end

def handle_call({:get, key}, state) do
{HashDict.get(state, key), state}
{Map.get(state, key), state}
end
end
end
@@ -72,7 +72,7 @@ end


defmodule TodoList do
defstruct auto_id: 1, entries: HashDict.new
defstruct auto_id: 1, entries: %{}

def new(entries \\ []) do
Enum.reduce(
@@ -87,7 +87,7 @@ defmodule TodoList do
entry
) do
entry = Map.put(entry, :id, auto_id)
new_entries = HashDict.put(entries, auto_id, entry)
new_entries = Map.put(entries, auto_id, entry)

%TodoList{todo_list |
entries: new_entries,
@@ -121,7 +121,7 @@ defmodule TodoList do

old_entry ->
new_entry = updater_fun.(old_entry)
new_entries = HashDict.put(entries, new_entry.id, new_entry)
new_entries = Map.put(entries, new_entry.id, new_entry)
%TodoList{todo_list | entries: new_entries}
end
end
@@ -131,6 +131,6 @@ defmodule TodoList do
%TodoList{entries: entries} = todo_list,
entry_id
) do
%TodoList{todo_list | entries: HashDict.delete(entries, entry_id)}
%TodoList{todo_list | entries: Map.delete(entries, entry_id)}
end
end
end
@@ -35,7 +35,7 @@ end


defmodule TodoList do
defstruct auto_id: 1, entries: HashDict.new
defstruct auto_id: 1, entries: %{}

def new(entries \\ []) do
Enum.reduce(
@@ -50,7 +50,7 @@ defmodule TodoList do
entry
) do
entry = Map.put(entry, :id, auto_id)
new_entries = HashDict.put(entries, auto_id, entry)
new_entries = Map.put(entries, auto_id, entry)

%TodoList{todo_list |
entries: new_entries,
@@ -84,7 +84,7 @@ defmodule TodoList do

old_entry ->
new_entry = updater_fun.(old_entry)
new_entries = HashDict.put(entries, new_entry.id, new_entry)
new_entries = Map.put(entries, new_entry.id, new_entry)
%TodoList{todo_list | entries: new_entries}
end
end
@@ -94,6 +94,6 @@ defmodule TodoList do
%TodoList{entries: entries} = todo_list,
entry_id
) do
%TodoList{todo_list | entries: HashDict.delete(entries, entry_id)}
%TodoList{todo_list | entries: Map.delete(entries, entry_id)}
end
end
end

0 comments on commit 51bc04b

Please sign in to comment.