Add Elixir examples for hash tables

This commit is contained in:
Evgeny Garlukovich
2018-02-06 21:31:07 +03:00
committed by Aditya Bhargava
parent 5d965d0b8a
commit 0c9424455e
2 changed files with 23 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
import Map, only: [put: 3]
book =
%{}
|> put("apple", 0.67)
|> put("milk", 1.49)
|> put("avocado", 1.49)
IO.inspect(book)

View File

@@ -0,0 +1,14 @@
defmodule Voting do
def check_voter(voters_map, name) do
if Map.has_key?(voters_map, name) do
IO.puts("kick them out!")
else
IO.puts("let them vote!")
Map.put(voters_map, name, true)
end
end
end
Voting.check_voter(%{}, "tom")
|> Voting.check_voter("mike")
|> Voting.check_voter("mike")