How do you check for the type of variable in Elixir

Low Kian Seong

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

>>> a = "test"
>>> type(a)
<type 'str'>
>>> b =10
>>> type(b)
<type 'int'>

I read in Elixir there are type checkers such as 'is_bitstring', 'is_float', 'is_list', 'is_map' etc, but what if you have no idea what the type could be ?

whatyouhide

There's no direct way to get the type of a variable in Elixir/Erlang.

You usually want to know the type of a variable in order to act accordingly; you can use the is_* functions in order to act based on the type of a variable.

Learn You Some Erlang has a nice chapter about typing in Erlang (and thus in Elixir).

The most idiomatic way to use the is_* family of functions would probably be to use them in pattern matches:

def my_fun(arg) when is_map(arg), do: ...
def my_fun(arg) when is_list(arg), do: ...
def my_fun(arg) when is_integer(arg), do: ...
# ...and so on

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do you check the uptime of a Phoenix/Elixir/Erlang application?

From Dev

How do you check the uptime of a Phoenix/Elixir/Erlang application?

From Java

In Elixir how do you initialize a struct with a map variable

From Java

How do you check if a variable is an array in JavaScript?

From Dev

How do you check if & variable is set in directive

From Dev

How to idiomatically check if a variable "is falsey" or "not true" in Elixir?

From Dev

How to check type of struct's field in Elixir?

From Dev

How do you pass a function as a parameter in Elixir?

From Java

How do you get duplicates in a list in elixir?

From Dev

How do you extend/inherit an elixir module?

From Dev

How do you define constants in Elixir modules?

From Dev

How do you conduct multiple trials in Elixir?

From Dev

How do you get the size of a file in Elixir?

From Dev

Elixir how do you sort a list comprehension?

From Dev

How do I check the type of my JQuery variable?

From Dev

how to check the type of a variable in swift

From Dev

How do you check if a cell in one dataset exists in another dataset's variable/column?

From Dev

In Elixir, how do you format numbers with string interpolation

From Dev

Elixir Logger - How do You Modify the Contents of a Logged Message?

From Dev

How do you handle base64 encoded files in Elixir?

From Dev

How do you embed double-quotes an Elixir string?

From Dev

Elixir Supervisors — How do you name a Supervised Task

From Dev

How do you check if a struct is initialized in C?

From Dev

How do you check for a scalar in R?

From Dev

How do you check an array for a range in Ruby?

From Dev

How do you check if a tag is present on a page?

From Java

How do you check "if not null" with Eloquent?

From Dev

How do you verify/check kivy version?

From Dev

How do you check the elements of a submatrix in Prolog

Related Related

  1. 1

    How do you check the uptime of a Phoenix/Elixir/Erlang application?

  2. 2

    How do you check the uptime of a Phoenix/Elixir/Erlang application?

  3. 3

    In Elixir how do you initialize a struct with a map variable

  4. 4

    How do you check if a variable is an array in JavaScript?

  5. 5

    How do you check if & variable is set in directive

  6. 6

    How to idiomatically check if a variable "is falsey" or "not true" in Elixir?

  7. 7

    How to check type of struct's field in Elixir?

  8. 8

    How do you pass a function as a parameter in Elixir?

  9. 9

    How do you get duplicates in a list in elixir?

  10. 10

    How do you extend/inherit an elixir module?

  11. 11

    How do you define constants in Elixir modules?

  12. 12

    How do you conduct multiple trials in Elixir?

  13. 13

    How do you get the size of a file in Elixir?

  14. 14

    Elixir how do you sort a list comprehension?

  15. 15

    How do I check the type of my JQuery variable?

  16. 16

    how to check the type of a variable in swift

  17. 17

    How do you check if a cell in one dataset exists in another dataset's variable/column?

  18. 18

    In Elixir, how do you format numbers with string interpolation

  19. 19

    Elixir Logger - How do You Modify the Contents of a Logged Message?

  20. 20

    How do you handle base64 encoded files in Elixir?

  21. 21

    How do you embed double-quotes an Elixir string?

  22. 22

    Elixir Supervisors — How do you name a Supervised Task

  23. 23

    How do you check if a struct is initialized in C?

  24. 24

    How do you check for a scalar in R?

  25. 25

    How do you check an array for a range in Ruby?

  26. 26

    How do you check if a tag is present on a page?

  27. 27

    How do you check "if not null" with Eloquent?

  28. 28

    How do you verify/check kivy version?

  29. 29

    How do you check the elements of a submatrix in Prolog

HotTag

Archive