1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

概要

paiza.ioでelixirやってみた。
Map使ってみた。

サンプルコード



m = %{a: 1, b: 2}
Map.delete(m, :a)
|> IO.inspect
Map.delete(m, :hoge)
|> IO.inspect
m = %{a: 1, b: 2, c: 3}
k = [:a, :b]
Map.drop(m, k)
|> IO.inspect
#ap.drop(m, [:hoge])
m = %{a: 1, b: 2}
m2 = %{a: 1, b: 2}
Map.equal?(m, m2)
|> IO.inspect
m = %{a: 1, b: 2, c: 3}
Map.fetch!(m, :a)
|> IO.inspect
#Map.fetch!(m, :hoge)
m = %{a: 1, b: 2, c: 3}
Map.fetch!(m, :a)
|> IO.inspect
#Map.fetch!(m, :hoge)
m = %{a: 1, b: 2, c: 3}
Map.get(m, :a)
|> IO.inspect
Map.get(m, :a, "default")
|> IO.inspect
Map.get(m, :hoge, "default")
|> IO.inspect
Map.get(m, :hoge)
|> IO.inspect
m = %{a: 1, b: 2, c: 3}
Map.has_key?(m, :a)
|> IO.inspect
Map.has_key?(m, :home)
|> IO.inspect
m = %{a: 1, b: 2, c: 3}
Map.keys(m)
|> IO.inspect
m = %{a: 1, b: 2}
m2 = %{c: 3, d: 4}
Map.merge(m, m2)
|> IO.inspect
m3 = %{a: 11, b: 22}
Map.merge(m, m3)
|> IO.inspect
Map.merge(m3, m)
|> IO.inspect
m = %{a: 1, b: 2}
m2 = %{a: 11, b: 22}
#Map.merge(m, m2, fn k, v1, v2 -> v1 end)
#Map.merge(m, m2, fn k, v1, v2 -> v2 end)
m3 = %{c: 3, d: 4}
#Map.merge(m, m3, fn k, v1, v2 -> v2 end)
Map.new()
|> IO.inspect
m = %{a: 1, b: 2, c: 3}
Map.pop(m, :a)
|> IO.inspect
{v, mm} = Map.pop(m, :a)
v
|> IO.inspect
mm
|> IO.inspect
Map.pop(m, :hoge)
|> IO.inspect
Map.pop(m, :hoge, "fuga")
|> IO.inspect
m = %{a: 1, b: 2}
Map.put(m, :c, 3)
|> IO.inspect
Map.put(m, :b, "hoge")
|> IO.inspect
m = %{a: 1, b: 2}
Map.put(m, :c, 3)
|> IO.inspect
Map.put(m, :b, "hoge")
|> IO.inspect
m = %{a: 1, b: 2}
Map.size(m)
|> IO.inspect
Map.size(%{})
|> IO.inspect
m = %{a: 1, b: 2, c: 3, d: 4, e: 5}
Map.split(m, [:b, :d])
|> IO.inspect
Map.split(m, [])
|> IO.inspect
m = %{a: 1, b: 2, c: 3, d: 4, e: 5}
Map.split(m, [:b, :d])
|> IO.inspect
Map.split(m, [])
|> IO.inspect
m = %{a: 1, b: 2, c: 3}
Map.to_list(m)
|> IO.inspect
Map.to_list(%{})
|> IO.inspect
m = %{a: 1, b: 2, c: 3}
Map.update!(m, :b, fn v -> 
	v * 2 
end)
|> IO.inspect
#Map.update!(m, :hoge, fn v -> 
#	v * 2 
#end)
#|> IO.inspect
m = %{a: 1, b: 2, c: 3}
Map.update(m, :b, "fuga", fn v -> 
	v * 2 
end)
|> IO.inspect
Map.update(m, :hoge, "fuga", fn v -> 
	v * 2 
end)
|> IO.inspect
m = %{a: 1, b: 2, c: 3}
Map.values(m)
|> IO.inspect





実行結果

%{b: 2}
%{a: 1, b: 2}
%{c: 3}
true
1
1
1
1
"default"
nil
true
false
[:a, :b, :c]
%{a: 1, b: 2, c: 3, d: 4}
%{a: 11, b: 22}
%{a: 1, b: 2}
%{}
{1, %{b: 2, c: 3}}
1
%{b: 2, c: 3}
{nil, %{a: 1, b: 2, c: 3}}
{"fuga", %{a: 1, b: 2, c: 3}}
%{a: 1, b: 2, c: 3}
%{a: 1, b: "hoge"}
%{a: 1, b: 2, c: 3}
%{a: 1, b: "hoge"}
2
0
{%{b: 2, d: 4}, %{a: 1, c: 3, e: 5}}
{%{}, %{a: 1, b: 2, c: 3, d: 4, e: 5}}
{%{b: 2, d: 4}, %{a: 1, c: 3, e: 5}}
{%{}, %{a: 1, b: 2, c: 3, d: 4, e: 5}}
[a: 1, b: 2, c: 3]
[]
%{a: 1, b: 4, c: 3}
%{a: 1, b: 4, c: 3}
%{a: 1, b: 2, c: 3, hoge: "fuga"}
[1, 2, 3]

成果物

以上。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?