Today I Learned

hashrocket A Hashrocket project

Determine type? no. Get info tho with `i`

There is no direct way to get a variable type in Elixir. For instance type("") is not something that exists although there are 15 Kernel methods for specific type determination such as:

iex > is_number(1)
true
iex > is_binary("") # Note that elixir checks for binary instead of string, a string is a binary.
true
iex > is_atom(:hey)
true

There is an i function available only in iex that will print out useful information about a variable.

iex > i("")
Term
  ""
Data type
  BitString
Byte size
  0
Description
  This is a string: a UTF-8 encoded binary. It's printed surrounded by
  "double quotes" because all UTF-8 encoded codepoints in it are printable.
Raw representation
  <<>>
Reference modules
  String, :binary

It's implemented as a protocol check it out.

I discovered it here.

See More #elixir TILs
Looking for help? At Hashrocket, we 💜 Elixir! From our many Elixir client projects, to sponsoring the Chicago Elixir Meetup, to the source code for this application, we are invested in this community. Contact us today to talk about your Elixir project.