How do you check for the type of variable in Elixir

前端 未结 8 1282
走了就别回头了
走了就别回头了 2021-01-30 15:25

In Elixir how do you check for type such as in Python:

>>> a = \"test\"
>>> type(a)

>>> b =10
>>> type(b         


        
8条回答
  •  余生分开走
    2021-01-30 16:01

    I just paste the code from https://elixirforum.com/t/just-created-a-typeof-module/2583/5 :)

    defmodule Util do
      types = ~w[function nil integer binary bitstring list map float atom tuple pid port reference]
      for type <- types do
        def typeof(x) when unquote(:"is_#{type}")(x), do: unquote(type)
      end
    end
    

提交回复
热议问题