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

5 minutes with Elixir

5 minutes with Elixir

My lightning talk from Brighton Ruby 2016 where we tour the highlights of Elixir and the surrounding ecosystem.

196ab25f16dcfd37518a41ceb15e0da0?s=128

Andy Pike

July 05, 2016
Tweet

Transcript

  1. NJOVUFTXJUI&MJYJS !BOEZQJLF

  2. None
  3. None
  4. None
  5. None
  6. None
  7. None
  8. None
  9. None
  10. None
  11. Hello Mike Hello Robert Hello Joe Erlang The Movie https://youtu.be/xrIjfIjssLE

  12. None
  13. None
  14. None
  15. defmodule Remark do def question?(remark) do String.ends_with?(remark, "?") end end

  16. "Brighton Ruby" |> String.upcase |> String.split # => ["BRIGHTON", "RUBY"]

  17. None
  18. String.ends_with?("Brighton Ruby", "y") # same as: "Brighton Ruby" |> String.ends_with?("y")

  19. None
  20. ["Brighton", language] = ["Brighton", "Ruby"] "Ruby" ["Brighton", language] = ["London",

    "Ruby"] ** (MatchError) no match of right hand side…
  21. None
  22. def convert(units, :miles_to_km) do units * 1.6 end def convert(units,

    :km_to_miles) do units / 1.6 end IO.puts convert(16, :km_to_miles) # => 10.0
  23. None
  24. spawn fn -> IO.puts "Doing work in a process" end

  25. None
  26. pid = spawn(fn -> ... end) send pid, :message

  27. None
  28. defmodule Brighton do def hello do receive do { :say,

    text } -> IO.puts(text) { :think, text } -> Logger.debug(text) end end end pid = spawn(Brighton, :hello, []) send pid, { :say, "Hello Brighton Ruby" }
  29. None
  30. None
  31. None
  32. 051 Open Telephony Protocol

  33. None
  34. {:ok, account} = GenServer.start(BankAccount, 0) GenServer.cast(account, {:deposit, 50}) GenServer.cast(account, {:withdraw,

    25})
  35. balance = GenServer.call(account, :balance) # => 25

  36. account = BankAccount.start(0) BankAccount.deposit(account, 50) BankAccount.withdraw(account, 25) BankAccount.balance(account) # =>

    25
  37. None
  38. Supervisor Supervisor Supervisor Supervisor Process Process Process Supervisor Process

  39. None
  40. None
  41. Framework Throughput (req/s) Phoenix 179,685 Sinatra 30,561 Rails 11,903 https://gist.github.com/omnibs/e5e72b31e6bd25caf39a

    * Needs re-running on latest versions ⚡
  42. http://www.phoenixframework.org/blog/the-road-to-2-million-websocket-connections

  43. $ mix phoenix.new hello $ cd hello $ mix ecto.create

    $ mix phoenix.server
  44. None
  45. [info] GET / [debug] Processing by Hello.PageController.index/2 Parameters: %{} Pipelines:

    [:browser] [info] Sent 200 in 198µs
  46. Router Controller View Template Smug Mode

  47. scope "/", Hello do pipe_through :browser get "/", PageController, :index

    resources "/users", UserController end Router
  48. defmodule Hello.PageController do use Hello.Web, :controller def index(conn, _params) do

    conn |> assign(:name, "Andy") |> render("index.html") end end Controller
  49. View defmodule Hello.PageView do use Hello.Web, :view def message do

    "Hello #{@name}!" end end
  50. None
  51. Template <h1><%= message %></h1> <p>Brighton Ruby is Ace!</p>

  52. None
  53. Metaprogramming Ecto Doctests Enum IEX Comprehensions Hot upgrades T ail

    Call Optimisation Mix Hex Credo ExUnit [ head | tail ] Nodes Plug
  54. None
  55. None
  56. elixir-lang.org exercism.io elixirschool.com elixirsips.com learnelixir.tv learnphoenix.tv elixirfountain.com codewars.com redfour.io

  57. None
  58. None
  59. None
  60. None
  61. None
  62. !BOEZQJLF

  63. @andypike