How to check dictionary type in Elixir

I want to check if the type of the parameter specified for a function in Elixir is a Dictionary. How to do it?

+5
source share
1 answer

First you need to know that Elixir supports 2 types of vocabulary

  • Erlangs native map type (for cards with a limited number of items)
    map = %{}
  • Elixirs proprietary dictionary type (dictionaries with potentially large payload)
    dict = HashDict.new

Both types should be checked with Erlangs native :erlang.is_map .

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

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

+2
source

Source: https://habr.com/ru/post/1204024/


All Articles