Elixir Sightseeing Tour

Elixir Sightseeing Tour

Faafc04d9e69b73b9f49995fd4c94d4d?s=128

Andrea Leopardi

September 26, 2019
Tweet

Transcript

  1. None
  2. None
  3. None
  4. None
  5. None
  6. None
  7. None
  8. None
  9. None
  10. None
  11. None
  12. None
  13. None
  14. None
  15. None
  16. None
  17. None
  18. None
  19. None
  20. None
  21. None
  22. None
  23. None
  24. None
  25. None
  26. None
  27. None
  28. defmodule Hello do def world() do IO.puts("Hello world") end end

  29. None
  30. None
  31. map = %{"conf" => "ClojuTRE"} new_map = Map.put(map, "conf", "smallFP")

    Map.get(map, "conf") #=> "ClojuTRE"
  32. Enum.map([1, 2, 3], fn n -> n * 2 end)

    #=> [2, 4, 6]
  33. None
  34. [first, _, "hello"] = my_list

  35. case some_expression do 1 -> "it's one!" {_, _} ->

    "it's a 2-elem tuple!" _other -> "it's something else" end
  36. text |> send_email(to, cc) send_email(text, to, cc)

  37. None
  38. send( set_status( put_cookie( set_session( add_cors_headers(request) ), cookie ), 200 )

    )
  39. request = add_cors_headers() request = set_session(request) request = put_cookie(request, cookie)

    request = set_status(request, 200) send(request)
  40. request |> add_cors_headers() |> set_session() |> put_cookie(cookie) |> set_status(200) |>

    send()
  41. None
  42. None
  43. None
  44. None
  45. None
  46. spawn(fn -> IO.puts("I'm in another process!") IO.inspect(self()) end)

  47. None
  48. None
  49. None
  50. None
  51. None
  52. None
  53. None
  54. None
  55. send(pid, "hello!")

  56. None
  57. None
  58. receive do
 message -> IO.puts("Received: #{message}") end

  59. None
  60. None
  61. send(dest_pid, {self(), {:add, 1, 7}}) receive do {:add_response, response} ->

    IO.puts("Response: #{response}") end
  62. None
  63. send(dest_pid, {self(), {:add, 1, 7}}) receive do {:add_response, response} ->

    IO.puts("Response: #{response}") after 1000 -> IO.puts("Timeout :(") end
  64. None
  65. None
  66. None
  67. None
  68. None
  69. None
  70. None
  71. ref = Process.monitor(dest_pid) send(dest_pid, {self(), {:add, 1, 7}}) receive do

    {:add_response, response} -> IO.puts("Response: #{response}") {:DOWN, ^ref, _, _, _} -> IO.puts("Process went down") after 1000 -> IO.puts("Timeout :(") end
  72. None
  73. None
  74. None
  75. None
  76. None
  77. None
  78. None
  79. None
  80. None
  81. None
  82. None
  83. None
  84. None
  85. None
  86. None
  87. None
  88. quote do add(1, 2) end

  89. two_code = quote do 1 + 1 end quote do

    add(1, unquote(two_code)) end
  90. if condition do expression end quote do case unquote(condition) do

    true -> unquote(expression) false -> nil end end
  91. None
  92. None
  93. None
  94. None
  95. None
  96. None