Elixir is a dynamic, functional language designed for building scalable and maintainable applications.
Elixir leverages the Erlang VM, known for running low-latency, distributed and fault-tolerant systems, while also being successfully used in web development and the embedded software domain.
As for which data structure to us here are some brief remarks.
If you need an array data structure if you're going to be doing a lot of writing use lists. If instead you are going to be doing a lot of read you should use tuples.
As for maps they are just simply how you do key value stores.
Note that the do...end
syntax is syntactic sugar for regular keyword lists, so you can actually do this:
unless false, do: IO.puts("Condition is false")
# Outputs "Condition is false"
# With an `else`:
if false, do: IO.puts("Condition is true"), else: IO.puts("Condition is false")
# Outputs "Condition is false"
Streams are composable, lazy enumerables.
Due to their laziness, streams are useful when working with large (or even infinite) collections. When chaining many operations with Enum
, intermediate lists are created, while Stream
creates a recipe of computations that are executed at a later moment.
A String
in Elixir is a UTF-8
encoded binary.
Elixir provides two associative data structures: maps and keyword lists.
Maps are the Elixir key-value (also called dictionary or hash in other languages) type.
Keyword lists are tuples of key/value that associate a value to a certain key. They are generally used as options for a function call.
In Elixir, module names such as IO
or String
are just atoms under the hood and are converted to the form :"Elixir.ModuleName"
at compile time.
iex(1)> is_atom(IO)
true
iex(2)> IO == :"Elixir.IO"
true
A note on structs
Instead of sharing protocol implementation with maps, structs require their own protocol implementation.
Note that the /rel
folder may not be needed in your .gitignore file. This is generated if you are using a release management tool such as exrm
So this is a summary analysis I've done based on the methods listed at How do you define constants in Elixir modules?. I'm posting it for a couple reasons:
I've also uploaded the entire code to the GitHub repo elixir-constants-concept.
Only works with Elixir 1.4+, but I can't tag that yet.
If you want to cover all data types you can define an implementation for Any
data type. Lastly, if you have time, check the source code of Enum and String.Char, which are good examples of polymorphism in core Elixir.