Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Intro to Elixir

Intro to Elixir

Presentation about Elixir programming language

Mario Alberto Chávez

November 05, 2015
Tweet

More Decks by Mario Alberto Chávez

Other Decks in Programming

Transcript

  1. Concurrency Lightweight processes |>Are applications |>Requires a minimum of 2k

    of memory |>Are supervised |>Fault-tolerant |>Garbage collected independent |>Run on multicore machines
  2. Concurrency Actor pattern |>Receive messages |>Process data |>Talk to other

    processes |>Start new processes |>Respond to messages
  3. Maps data = %{ name: “Mario”, language: “Elixir” } data.name

    => “Mario” data[:language] => “Elixir
  4. Keywords List data = [name: “Mario”, 
 language: “Elixir”] data[:name]

    => “Mario” data.name ** (ArgumentError) argument error
  5. Functions adder = fn(a) -> fn(b) -> a + b

    end end add2 = adder.(2) add.(3) => 5
  6. Inline functions Enum.map([1, 2], fn(value) -> value * value end)

    => [1, 4] Enum.map([1, 2], &(&1 * &1)) => [1, 4]
  7. Match operator = a = 1 => 1 1 =

    a => 1 2 = a ** (MatchError) no match of 
 right hand side value: 1 ^a = 2 ** (MatchError) no match of 
 right hand side value: 2
  8. Deconstruction list = [1, 3, 5, 7] [1, a |

    tail] = list a => 3 tail => [5, 7]
  9. Multiple clauses require Integer, only: [is_odd/1] defmodule Math do def

    mult(0), do: 0 def mult(x) when Integer.is_odd(x), do: x * 3 def mult(x), do: x * -3 end Math.mult(0) => 0 Math.mult(3) => 9 Math.mult(6) => -18
  10. Pipeline [7, nil, 3, nil, 5, 1] 
 |> Enum.filter(&(&1))

    
 |> Enum.sort 
 |> Enum.map(&(&1 * 2)) 
 |> Enum.join(", ") => ”2, 6, 10, 14"