what is this elixir thing everyone is talking about

what is this elixir thing everyone is talking about

some of my fav features of elixir

lightning talk for CodeDaze.io on September 16th, 2016

570a76d7545a0ae4b693ffee5435717e?s=128

José Tomás Albornoz

September 16, 2016
Tweet

Transcript

  1. what is this elixir thing everyone's talking about by jojo

  2. what is elixir

  3. elixir is a functional language

  4. created by José Valim

  5. that runs on the erlang vm

  6. pattern matching iex(1)> [first, second] = [1, 2] [1, 2]

    iex(2)> first 1
  7. pattern matching iex(2)> [first, second] = [1,2,3] ** (MatchError) no

    match of right hand side value: [1, 2, 3]
  8. pattern matching iex(1)> payload = %{username: "eljojo", stuff: true} %{stuff:

    true, username: "eljojo"} iex(2)> %{username: name} = payload %{stuff: true, username: "eljojo"} iex(3)> name "eljojo"
  9. function overloading def make_sound(:cow) do IO.puts "MOOOOOOOOO" end def make_sound(:cat)

    do IO.puts "MEEEOOWW" end def make_sound(_) do IO.puts "¯\_(ϑ)_/¯" end
  10. function overloading def make_sound(%{animal: :cow}) do IO.puts "MOOOOOOOOO" end def

    make_sound(%{animal: :cat}) do IO.puts "MEEEOOWW" end def make_sound(%{animal: name}) do IO.puts "not sure how to #{name} ¯\_(ϑ)_/¯" end
  11. we also got guards def page_ops(downtime) when downtime < 10

    do IO.puts "¯\_(ϑ)_/¯" end def page_ops(downtime) when downtime >= 10 do PagerDuty.notify(whatever) end
  12. pipe operator def add_one(number), do: number + 1 def multiply_by_three(number),

    do: number * 3 multiply_by_three(add_one(1)) # => 6
  13. pipe operator def add_one(number), do: number + 1 def multiply_by_three(number),

    do: number * 3 1 |> add_one |> multiply_by_three # => 6
  14. processes + messages current_process = self() spawn_link(fn -> send(current_process, {:msg,

    "hello world"}) end) receive do {:msg, contents} -> IO.puts contents end
  15. processes + messages # machine one receive do {:msg, contents}

    -> IO.puts contents end # machine two process_name = "$MACHINE_ONE" spawn_link(fn -> send(process_name, {:msg, "yo!"}) end)
  16. what is phoenix

  17. A productive web framework that does not compromise speed and

    maintainability.
  18. it's basically rails for elixir, but cooler

  19. validations def changeset(struct, params \\ %{}) do struct |> cast(params,

    [:email_address, :first_name]) |> validate_required([:email_address]) end def changeset_after_signup(struct, params \\ %{}) do changeset(struct, params) |> validate_required([:first_name]) end
  20. we're hiring!

  21. @eljojo