learn elixir at manchester lambda lounge

37
Learn Elixir Manchester Lambda Lounge, Monday 20 Feb 2017, 7pm Presented by Chi-chi Ekweozor @thisischichi

Upload: chi-chi-ekweozor

Post on 12-Apr-2017

293 views

Category:

Software


4 download

TRANSCRIPT

Page 1: Learn Elixir at Manchester Lambda Lounge

Learn ElixirManchester Lambda Lounge, Monday 20 Feb 2017, 7pm

Presented by Chi-chi Ekweozor @thisischichi

Page 2: Learn Elixir at Manchester Lambda Lounge

“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.”

Page 3: Learn Elixir at Manchester Lambda Lounge

• 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’

Page 4: Learn Elixir at Manchester Lambda Lounge

Learn Elixir

• Install Elixir

• What is pattern matching?

• Meet Lists, and Modules

• Meet the Pipe Operator |>

• Resources for learning

Page 5: Learn Elixir at Manchester Lambda Lounge

Install Elixir

Page 6: Learn Elixir at Manchester Lambda Lounge

To install Elixir on your computer, follow the instructions at:

http://elixir-lang.org/install.html

Page 7: Learn Elixir at Manchester Lambda Lounge

iex - Interactive Elixir

To test your Elixir installation was successful, start an Elixir session. At your regular shell prompt, type iex.

Page 8: Learn Elixir at Manchester Lambda Lounge

Elixir Basics

Page 9: Learn Elixir at Manchester Lambda Lounge

Learn Elixir

• Install Elixir

• What is pattern matching?

• Meet Lists, and Modules

• Meet the Pipe Operator |>

• Resources for learning

Page 10: Learn Elixir at Manchester Lambda Lounge

Pattern matching?

Page 11: Learn Elixir at Manchester Lambda Lounge

Type this into your terminal: iex> a = 1 iex> a + 3

Page 12: Learn Elixir at Manchester Lambda Lounge

Now, type this into your terminal: iex> a = 1 iex> 1 = a iex> 2 = a

Page 13: Learn Elixir at Manchester Lambda Lounge

Lists, and pattern matching: iex> list = [ 1, 2, 3 ] iex> [ a, b, c ] = list

iex> a, iex> b, etc etc

Page 14: Learn Elixir at Manchester Lambda Lounge

More lists: iex> list = [ 1, 2, 3 ] iex> [ a, 2, b ] = list

iex> a, iex> b, etc etc

Page 15: Learn Elixir at Manchester Lambda Lounge

There’s more to this than might be immediately apparent:

iex> list = [ 1, 2, 3 ] iex> [ a, 1, b ] = list

Page 16: Learn Elixir at Manchester Lambda Lounge

Learn Elixir

• Install Elixir

• What is pattern matching?

• Meet Lists, and Modules

• Meet the Pipe Operator |>

• Resources for learning

Page 17: Learn Elixir at Manchester Lambda Lounge

Now meet Modules

Page 18: Learn Elixir at Manchester Lambda Lounge
Page 19: Learn Elixir at Manchester Lambda Lounge
Page 20: Learn Elixir at Manchester Lambda Lounge
Page 21: Learn Elixir at Manchester Lambda Lounge
Page 22: Learn Elixir at Manchester Lambda Lounge

clause

Page 23: Learn Elixir at Manchester Lambda Lounge
Page 24: Learn Elixir at Manchester Lambda Lounge
Page 25: Learn Elixir at Manchester Lambda Lounge

Learn Elixir

• Install Elixir

• What is pattern matching?

• Meet Lists, and Modules

• Meet the Pipe Operator |>

• Resources for learning

Page 26: Learn Elixir at Manchester Lambda Lounge

The Pipe Operator |>

Page 27: Learn Elixir at Manchester Lambda Lounge

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)

Page 28: Learn Elixir at Manchester Lambda Lounge

The alternative was to write:

filing = prepare_filing(sales_tax(Orders.for_customers(DB.find_customers), 2016))

Page 29: Learn Elixir at Manchester Lambda Lounge

Elixir has a better way of writing it…

Page 30: Learn Elixir at Manchester Lambda Lounge

The Pipe or Pipeline Operator |> takes the result of the previous

expression and feeds it to the next one as the first argument

Page 31: Learn Elixir at Manchester Lambda Lounge

In Elixir, the awkward to read function becomes:

Page 32: Learn Elixir at Manchester Lambda Lounge

filing = DB.find_customers

|> Orders.for_customers

|> sales_tax(2016)

|> prepare_filing

Page 33: Learn Elixir at Manchester Lambda Lounge

Putting it all together, a |> exercise:

Page 34: Learn Elixir at Manchester Lambda Lounge
Page 35: Learn Elixir at Manchester Lambda Lounge

Learn Elixir

• Install Elixir

• What is pattern matching?

• Meet Lists, and Modules

• Meet the Pipe Operator |>

• Resources for learning

Page 36: Learn Elixir at Manchester Lambda Lounge

Learning Resources

Page 37: Learn Elixir at Manchester Lambda Lounge

Books:

Programming Elixir 1.3 by Dave Thomas

Elixir in Action by Saša Jurić

Websites:

elixir-lang.org

elixirforum.com

elixirschool.com