Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check for a Dictionary Type in Elixir

Tags:

elixir

I want to check if the type of a parameter given to a function in Elixir is a Dictionary. How do I do this?

like image 767
robkuz Avatar asked Oct 31 '22 16:10

robkuz


1 Answers

First you have to be aware that Elixir supports 2 Dictionary types

  • Erlangs native Map type (for maps with only limited items)
    map = %{}
  • Elixirs own Dictionary type (dictionaries with a potentially large payload)
    dict = HashDict.new

Both types however need to be checked with Erlangs native :erlang.is_map.

def some_fun(arg) when :erlang.is_map(arg) do
    #do your thing
end

More info can be found under sections 7.2 and 7.3 (http://elixir-lang.org/getting_started/7.html)

like image 176
robkuz Avatar answered Nov 15 '22 08:11

robkuz