5
2

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.

口で言うより行うことがErlang習得への近道と信じています。

マップとは

キーと値の関連付けを持つ複合データ型です。どんな型のキーも使え、順序付けされません。 マップは#{}構文で定義することができます。

> M1 = #{name => "Inoki", id => 123, birthday => {1943, 02, 20}}.
#{birthday => {1943,2,20},id => 123,name => "Inoki"}

> maps:get(name, M1).
"Inoki"

> maps:update(name, "Antonio Inoki", M1).
#{birthday => {1943,2,20},id => 123,name => "Antonio Inoki"}

> map_size(M1).
3

変数をマップのキーにすることもできます。

> Key = "hello".
"hello"

> #{Key => "world"}.
#{"hello" => "world"}

重複したキーが追加された場合は、前の値が置き換えられます。

> #{foo => "bar", foo => "hello world"}.
#{foo => "hello world"}

マップの更新のための固有の構文があります。便宜上「更新」と言っていますが、実際には新しいマップが作成されます。

> M2 = #{aisatsu => "Hello", message => "How are you?"}.
#{aisatsu => "Hello",message => "How are you?"}

> M2#{message => "Genki desu ka----!"}.
#{aisatsu => "Hello",message => "Genki desu ka----!"}

マップ操作のための関数はmapsモジュールにあります。

Elixirにも挑戦したい

闘魂ElixirシリーズとElixir Schoolがオススメです。

5
2
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
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?