Elixir
Functional highly scalable language for realtime data built on Erlang VM allowing usage of Erlang libs/functions like OTP.
Ruby on Rails-like immutable, dynamically typed, functional language
Runs inside lightweight threads(called processes) communicating via messages even if on different machines so legit horizontal scale(Erlang VM handles multi-machine, can also implement with Redis)
Elixir uses supervisers and processes fail fast. If there is an error, restart in proper/known state
Hex package manager
Elixir used by Brex, Tandem, Pagerduty
Inline code tests
Pure Functional
no class with internal state, but modules that init or transform an input state and return new state
Not indexable list, but recursive head rest pattern matching
To dealing with state across processes, use Erlang Term Storage(ETS) or processes like Agents, Genserver
Opinated(variables must be camelcase and modules CamelCase)
Basic
Double and triple equals like javascript(type conversion vs no type conversion)
if age === 18 do [.] else [.] end
, ruby unless, switch => case, long if else can be cond similar to OcamlLike erlang, function returns the last value
Can't do for (int ....) b/c immutable, must use recursion
=
operator is actually called the match operatorsomeFunction/2
means someFunction with two args as functions unique by name & arg count(arity)or
,and
,not
and can short circuit==
,!=
,===
(doesn't count integers and floats as equal, but works at comparing native objects! [1,2] === [1,2]),!==
,<=
,>=
,<
and>
Use pin operator
^
to pattern match against variables cur value:x = 1 ^x = 2
=> Error no match 1 = 2 ( apparently also used in queries for type coercion)"a"
is UTF-8 encoded binary while'a'
is charlist
test.exs
Doesn't actually need main or anything
IO
Print internal representation
IO.inspect [97, 98]
=> [a,b]
IO.inspect [97, 98], char_lists: :as_lists
=> [97, 98]
Branches
Trenary op
Conditional Matching, goes to first match
switch
With
In the code snippet above we've rewrite nested case
clauses with with
. Within with
we invoke some functions (either anonymous or named) and pattern match on their outputs. If all matched, with
return do
block result, or else
block result otherwise.
We can omit else
so with
will return either do
block result or the first fail result.
System Variables
Type Converstion
Last updated