LoginSignup
13
11

More than 5 years have passed since last update.

Elixir のコレクション型のまとめ

Last updated at Posted at 2015-10-22

概要

他の言語でいう配列、リスト、マップ、ディクショナリーのようなコレクション型についてまとめました。

環境

  • Elixir 1.1.1
  • Erlang/OTP 18 [erts-7.1]

tuple

データやサイズの取得が早いリスト。更新は linked list より遅い。

{"abc", :def, 3, true}

主な操作

linked list

データの更新が早いリスト。データの取得やサイズの取得は tuple より遅い。

["abc", :def, 3, true]

主な操作

map

key-value ストア。

%{ "abc" => :xyz, :def => "lmn", 2 => true} 

主な操作

Range

数字の範囲を表します。

1..10

主な操作

keyword list

key-value ストア。key は atom のみ。
特殊な tuple の linked list なので linked list と同じ特徴を持っています。

[abc: "xyz", def: true, h: :lmn]
[{:abc, "xyz"}, {:def, true}, {:h, :lmn}]

主な操作

HashDict

将来廃止予定。 map に十分なパフォーマンスがあります(erlang 18以降)。
key-value ストア。 データ量が多いときに map や keyword list より効率的に動作します。

MapSet

ユニークな値のリスト。

[:sunday, :monday, :tuesday] |> Enum.into(MapSet.new)

主な操作

HashSet

将来廃止予定MapSet を使ってください。

参考

13
11
4

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
13
11