learn elixir at manchester lambda lounge
TRANSCRIPT
Learn ElixirManchester Lambda Lounge, Monday 20 Feb 2017, 7pm
Presented by Chi-chi Ekweozor @thisischichi
“Elixir is a dynamic, functional language with Ruby-like syntax that runs on the Erlang virtual machine. It can be described as the language
for the modern, real time, hyper-connected world with first class support for concurrency,
fault tolerance and high availability, all courtesy of its Erlang pedigree.”
• Elixir is a functional language. There are two things to remember:
Immutable data: any function that transforms data will return a new copy of it
We can combine functions, and run them in parallel if we please, using lightweight Elixir ‘processes’
Learn Elixir
• Install Elixir
• What is pattern matching?
• Meet Lists, and Modules
• Meet the Pipe Operator |>
• Resources for learning
Install Elixir
To install Elixir on your computer, follow the instructions at:
http://elixir-lang.org/install.html
iex - Interactive Elixir
To test your Elixir installation was successful, start an Elixir session. At your regular shell prompt, type iex.
Elixir Basics
Learn Elixir
• Install Elixir
• What is pattern matching?
• Meet Lists, and Modules
• Meet the Pipe Operator |>
• Resources for learning
Pattern matching?
Type this into your terminal: iex> a = 1 iex> a + 3
Now, type this into your terminal: iex> a = 1 iex> 1 = a iex> 2 = a
Lists, and pattern matching: iex> list = [ 1, 2, 3 ] iex> [ a, b, c ] = list
iex> a, iex> b, etc etc
More lists: iex> list = [ 1, 2, 3 ] iex> [ a, 2, b ] = list
iex> a, iex> b, etc etc
There’s more to this than might be immediately apparent:
iex> list = [ 1, 2, 3 ] iex> [ a, 1, b ] = list
Learn Elixir
• Install Elixir
• What is pattern matching?
• Meet Lists, and Modules
• Meet the Pipe Operator |>
• Resources for learning
Now meet Modules
clause
Learn Elixir
• Install Elixir
• What is pattern matching?
• Meet Lists, and Modules
• Meet the Pipe Operator |>
• Resources for learning
The Pipe Operator |>
We’ve all seen code like this:
people = DB.find_customers
orders = Orders.for_customers(people)
tax = sales_tax(orders, 2016)
filing = prepare_filing(tax)
The alternative was to write:
filing = prepare_filing(sales_tax(Orders.for_customers(DB.find_customers), 2016))
Elixir has a better way of writing it…
The Pipe or Pipeline Operator |> takes the result of the previous
expression and feeds it to the next one as the first argument
In Elixir, the awkward to read function becomes:
filing = DB.find_customers
|> Orders.for_customers
|> sales_tax(2016)
|> prepare_filing
Putting it all together, a |> exercise:
Learn Elixir
• Install Elixir
• What is pattern matching?
• Meet Lists, and Modules
• Meet the Pipe Operator |>
• Resources for learning
Learning Resources
Books:
Programming Elixir 1.3 by Dave Thomas
Elixir in Action by Saša Jurić
Websites:
elixir-lang.org
elixirforum.com
elixirschool.com