Shih-Min Lee
Shih-Min Lee

Reputation: 9750

Picking properties of a map from a list in Elixir

Is there a way to pick properties of a map from a list in elixir?

map = %{
  a: 1, b: 2, c: 3
}

do_something(map, [:a, :b]) = %{a: 1, b: 2}

Upvotes: 0

Views: 215

Answers (1)

José Valim
José Valim

Reputation: 51439

You want Map.take/2:

iex> Map.take(%{a: 1, b: 2, c: 3}, [:a, :b])
%{a: 1, b: 2}

Upvotes: 1

Related Questions