iex> 40 + 2
42
iex> "hello" <> " world"
"hello world"
$ elixir simple.exs
Hello world from Elixir
iex> 1 # integer
iex> 0x1F # integer
iex> 1.0 # float
iex> true # boolean
iex> :atom # atom
iex> "elixir" # string
iex> [1, 2, 3] # list
iex> {1, 2, 3} # tuple
Atoms are constants where their name is their own value. Some other languages call these symbols:
iex> :hello
:hello
iex> :hello == :world
false
iex> true == :true
true
iex> is_atom(false)
true
iex> is_boolean(:false)
true
iex> send self(), {:hello, "world"}
{:hello, "world"}
iex> receive do
...> {:hello, msg} -> msg
...> {:world, msg} -> "won't match"
...> end
"world"
iex> receive do
...> {:hello, msg} -> msg
...> after
...> 1_000 -> "nothing after 1s"
...> end
"nothing after 1s"
The Enum module provides a huge range of functions to transform, sort, group, filter and retrieve items from enumerables. It is one of the modules developers use frequently in their Elixir code.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi nec metus justo. Aliquam erat volutpat.
$ mix new kv --module KV
* creating README.md
* creating .gitignore
* creating mix.exs
* creating config
* creating config/config.exs
* creating lib
* creating lib/kv.ex
* creating test
* creating test/test_helper.exs
* creating test/kv_test.exs
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi nec metus justo. Aliquam erat volutpat.