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

Pinball Elixir

Pinball Elixir

Intro to Elixir with Pinball

Adrian Dunston

October 14, 2019
Tweet

More Decks by Adrian Dunston

Other Decks in Technology

Transcript

  1. Pinball
    Elixir
    with Adrian P. Dunston

    View Slide

  2. @bitcapulet
    Purpose
    To get you excited
    about Elixir.
    2

    View Slide

  3. @bitcapulet
    Purpose
    To get you excited
    about Elixir. So you’ll be
    more powerful.
    3

    View Slide

  4. @bitcapulet
    Purpose
    To get you excited
    about Elixir. So you’ll be
    more powerful. So your
    companies will start using it.
    4

    View Slide

  5. @bitcapulet
    Purpose
    To get you excited
    about Elixir. So you’ll be
    more powerful. So your
    companies will start using it. So my
    friends and I have more Elixir jobs available.
    5

    View Slide

  6. @bitcapulet
    Purpose
    To get you excited
    about Elixir. So you’ll be
    more powerful. So your
    companies will start using it. So my
    friends and I have more Elixir jobs available.
    Because I'm excited about Elixir.
    6

    View Slide

  7. @bitcapulet
    Story Time!
    7

    View Slide

  8. @bitcapulet
    Story Time!
    Kevin McAbee
    8

    View Slide

  9. @bitcapulet

    View Slide

  10. @bitcapulet

    View Slide

  11. @bitcapulet

    View Slide

  12. @bitcapulet
    Story Time!
    Kevin McAbee
    12

    View Slide

  13. @bitcapulet13

    View Slide

  14. @bitcapulet14

    View Slide

  15. @bitcapulet15

    View Slide

  16. @bitcapulet16

    View Slide

  17. Adrian P. Dunston
    [email protected]
    @bitcapulet
    17
    joinpapa.com

    View Slide

  18. 18
    Adrian P. Dunston
    [email protected]
    @bitcapulet
    18
    joinpapa.com

    View Slide

  19. @bitcapulet
    What is
    essential?
    19

    View Slide

  20. @bitcapulet
    State complexity clearly.
    Steal from telephony.
    20

    View Slide

  21. @bitcapulet
    Elixir does two things very well.
    21

    View Slide

  22. @bitcapulet
    If you state your complexity clearly,
    it's easier to solve complex problems.
    22

    View Slide

  23. @bitcapulet
    If you state your complexity clearly,
    it's easier to solve complex problems.
    Distributed systems =
    complex problems
    23

    View Slide

  24. @bitcapulet
    If you state your complexity clearly,
    it's easier to solve complex problems.
    Functional programming
    forces this.
    24

    View Slide

  25. @bitcapulet
    If you state your complexity clearly,
    it's easier to solve complex problems.
    This is what ELIXIR
    brings to the table.
    25

    View Slide

  26. @bitcapulet
    Rob those phone companies blind!
    26

    View Slide

  27. @bitcapulet
    Rob those phone companies blind!
    16 years of searching and building.
    27

    View Slide

  28. @bitcapulet
    Rob those phone companies blind!
    16 years of searching and building.
    THEN 20 years of open-source
    improvements.
    28

    View Slide

  29. @bitcapulet
    Rob those phone companies blind!
    16 years of searching and building.
    THEN 20 years of open-source
    improvements.
    29
    Now a fresh new language built on top!

    View Slide

  30. @bitcapulet
    State complexity clearly.
    30

    View Slide

  31. @bitcapulet
    State complexity clearly.
    Steal from telephony.
    31

    View Slide

  32. @bitcapulet
    Magic
    Matching
    State complexity clearly.
    32

    View Slide

  33. @bitcapulet33

    View Slide

  34. @bitcapulet34

    View Slide

  35. @bitcapulet35

    View Slide

  36. @bitcapulet36

    View Slide

  37. @bitcapulet37

    View Slide

  38. @bitcapulet38

    View Slide

  39. @bitcapulet39

    View Slide

  40. @bitcapulet40

    View Slide

  41. @bitcapulet41

    View Slide

  42. @bitcapulet42

    View Slide

  43. @bitcapulet
    42
    43

    View Slide

  44. @bitcapulet
    'a'
    44

    View Slide

  45. @bitcapulet
    [1,2]
    45

    View Slide

  46. @bitcapulet
    :ok
    46

    View Slide

  47. @bitcapulet
    :ok
    ?
    47

    View Slide

  48. @bitcapulet
    :ok
    :oj
    :ol
    48

    View Slide

  49. @bitcapulet
    :ok
    :oj
    :ol
    :error
    :erroq
    :erros
    :adrian
    :adriam
    :adriao
    49

    View Slide

  50. @bitcapulet50

    View Slide

  51. @bitcapulet51

    View Slide

  52. @bitcapulet
    Plunger
    52

    View Slide

  53. @bitcapulet
    Plunger
    53

    View Slide

  54. @bitcapulet
    Plunger
    Playfield
    54

    View Slide

  55. @bitcapulet
    Plunger
    Playfield
    55

    View Slide

  56. @bitcapulet
    Plunger
    Playfield
    56

    View Slide

  57. @bitcapulet
    Plunger
    Playfield Drain
    57

    View Slide

  58. @bitcapulet
    Plunger
    Playfield Drain
    58

    View Slide

  59. @bitcapulet
    def run(ball) do
    ball
    end
    59

    View Slide

  60. @bitcapulet
    def run(ball) do
    ball;
    end
    60

    View Slide

  61. @bitcapulet
    def run(ball) do
    return ball;
    end
    61

    View Slide

  62. @bitcapulet
    def run(ball) do
    ball
    end
    Drain
    62

    View Slide

  63. @bitcapulet63

    View Slide

  64. @bitcapulet64

    View Slide

  65. @bitcapulet65

    View Slide

  66. @bitcapulet66

    View Slide

  67. @bitcapulet
    def run(a,b,c,d) do
    # ummm...
    end
    67

    View Slide

  68. @bitcapulet
    def run(a,b,c,d) do
    [d,c,b,a]
    end
    68

    View Slide

  69. @bitcapulet69

    View Slide

  70. @bitcapulet
    def run(a,b,c,d) do
    [d,c,b,a]
    end
    70

    View Slide

  71. @bitcapulet71

    View Slide

  72. @bitcapulet72

    View Slide

  73. @bitcapulet73

    View Slide

  74. @bitcapulet
    [ , , , ]
    74

    View Slide

  75. @bitcapulet
    [ , , , ]
    a b c d
    75

    View Slide

  76. @bitcapulet
    [ , , , ]
    a b c d
    def get_odd(list) do
    a = Enum.at(list, 0)
    c = Enum.at(list, 2)
    [a, c]
    end
    76

    View Slide

  77. @bitcapulet77

    View Slide

  78. @bitcapulet
    [a, b, c, d] [ , , , ]
    78

    View Slide

  79. @bitcapulet
    [ , , , ]
    [ , , , ]
    79

    View Slide

  80. @bitcapulet
    [ , , , ]
    [ , , , ]
    80

    View Slide

  81. @bitcapulet
    [ , , , ]
    [ , , , ]
    81

    View Slide

  82. @bitcapulet
    [ , , , ]
    [ , , , ]
    82

    View Slide

  83. @bitcapulet
    [ , , , ]
    a b c d
    def get_odd(list) do
    a = Enum.at(list, 0)
    c = Enum.at(list, 2)
    [a, c]
    end
    83

    View Slide

  84. @bitcapulet
    [ , , , ]
    a b c d
    def get_odd(list) do
    [a, b, c, d] list
    [a, c]
    end
    84

    View Slide

  85. @bitcapulet
    [ , , , ]
    a b c d
    def get_odd(list) do
    [a, _, c, _] list
    [a, c]
    end
    85

    View Slide

  86. @bitcapulet
    [ , , , ]
    a b c d
    def get_odd(list) do
    [a, _b, c, _d] list
    [a, c]
    end
    86

    View Slide

  87. @bitcapulet
    Captive Ball
    87

    View Slide

  88. @bitcapulet
    Multiball!!
    88

    View Slide

  89. @bitcapulet
    Kicker
    89

    View Slide

  90. @bitcapulet90

    View Slide

  91. @bitcapulet91

    View Slide

  92. @bitcapulet
    %{name: "Adrian"}
    92

    View Slide

  93. @bitcapulet
    %{name: "Adrian"}
    jsObject = {"name": "Adrian"}
    93

    View Slide

  94. @bitcapulet
    Map map =
    new HashMap();
    map.put("name","Adrian");
    94

    View Slide

  95. @bitcapulet
    %{name: "Adrian"}
    95

    View Slide

  96. @bitcapulet
    %{
    name: "Adrian",
    age: 40,
    fav_capt: "Picard"
    }
    96

    View Slide

  97. @bitcapulet
    human = %{
    name: "Adrian",
    age: 40,
    fav_capt: "Picard"
    }
    97

    View Slide

  98. @bitcapulet
    human = %{
    name: "Adrian",
    age: 40,
    fav_capt: "Picard"
    }
    98

    View Slide

  99. @bitcapulet
    human = %{
    name: ,
    age: ,
    fav_capt:
    }
    99

    View Slide

  100. @bitcapulet
    human
    100

    View Slide

  101. @bitcapulet
    %{name: var} human
    101

    View Slide

  102. @bitcapulet
    %{name: var}
    human
    102

    View Slide

  103. @bitcapulet
    %{name: var}
    human
    103

    View Slide

  104. @bitcapulet
    %{name: var} human
    104

    View Slide

  105. @bitcapulet
    %{name: var}
    "Adrian"
    human
    105

    View Slide

  106. @bitcapulet
    def get_name(map) do
    %{name: var} map
    var
    end
    106

    View Slide

  107. @bitcapulet
    def get_name(map) do
    %{name: var} map
    var
    end
    get_name(%{})
    107

    View Slide

  108. @bitcapulet
    get_name(%{})
    108

    View Slide

  109. @bitcapulet
    get_name(%{})
    %{}
    109

    View Slide

  110. @bitcapulet
    %{}
    Cookie Monster
    CONFIRMED!!
    110

    View Slide

  111. @bitcapulet
    %{ }
    Cookie Monster
    CONFIRMED!!
    111

    View Slide

  112. @bitcapulet
    %{0}
    Cookie Monster
    CONFIRMED!!
    112

    View Slide

  113. @bitcapulet
    %{}
    Cookie Monster
    CONFIRMED!!
    113

    View Slide

  114. @bitcapulet
    %{*}
    Cookie Monster
    CONFIRMED!!
    114

    View Slide

  115. @bitcapulet
    %{}
    Cookie Monster
    CONFIRMED!!
    115

    View Slide

  116. @bitcapulet
    %{.}
    Cookie Monster
    CONFIRMED!!
    116

    View Slide

  117. @bitcapulet
    %{}
    Cookie Monster
    CONFIRMED!!
    117

    View Slide

  118. @bitcapulet
    %{}
    Me love it!
    118

    View Slide

  119. @bitcapulet119

    View Slide

  120. @bitcapulet
    def get_name(map) do
    %{name: var} map
    var
    end
    get_name(%{})
    120

    View Slide

  121. @bitcapulet
    def get_name(map) do
    %{name: var} map
    var
    end
    get_name(%{})
    ** (MatchError) no match of
    right hand side value: %{}
    121

    View Slide

  122. @bitcapulet
    %{}
    What you mean
    let process
    fail?!
    122

    View Slide

  123. @bitcapulet123

    View Slide

  124. @bitcapulet124

    View Slide

  125. @bitcapulet
    def get_name(map) do
    %{name: var} map
    var
    end
    get_name(%{})
    ** (MatchError) no match of
    right hand side value: %{}
    125
    Not just for getting values!

    View Slide

  126. @bitcapulet
    %{name: _,
    age: _,
    fav_capt: _
    } my_map
    126

    View Slide

  127. @bitcapulet
    %{"name" => _,
    "age" => _,
    "fav.capt." => "Picard"
    } my_map
    %{name: _,
    age: _,
    fav_capt: "Picard"
    } my_map
    127

    View Slide

  128. @bitcapulet128

    View Slide

  129. @bitcapulet
    %{"name" => _,
    "age" => _,
    "fav.capt." => "Picard"
    } my_map
    %{name: _,
    age: _,
    fav_capt: "Picard"
    } my_map
    129

    View Slide

  130. @bitcapulet
    %{"name" => _,
    "age" => _,
    "fav.capt." => "Picard"
    } my_map
    [
    %{fav_capt: "Kirk"},
    %{fav_capt: "Picard"},
    %{fav_capt: "Sisko"},
    %{fav_capt: "Janeway"},
    ] list_of_maps
    130

    View Slide

  131. @bitcapulet
    %{"name" => _,
    "age" => _,
    "fav.capt." => "Picard"
    } my_map
    [
    %{fav_capt: "Kirk"},
    %{fav_capt: "Picard"},
    %{fav_capt: "Sisko"},
    %{fav_capt: "Janeway"},
    %{fav_capt: ["Kirk", "Sisko"]
    ] list_of_maps_with_lists
    131

    View Slide

  132. @bitcapulet
    %{"name" => _,
    "age" => _,
    "fav.capt." => "Picard"
    } my_map
    [
    %{fav_capt: "Kirk", age: var},
    %{fav_capt: "Picard"},
    %{fav_capt: "Sisko"},
    %{fav_capt: "Janeway"},
    %{fav_capt: ["Kirk", "Sisko"]
    ] list_of_maps_with_lists
    132

    View Slide

  133. @bitcapulet
    [ , , , ] [ , , , ]
    133
    VALUES!

    View Slide

  134. @bitcapulet
    [ , , , ]
    [ , , , ]
    134
    VALUES!

    View Slide

  135. @bitcapulet
    [ , , , ]
    [ , , , ]
    135
    VALUES!

    View Slide

  136. @bitcapulet
    [ , , , ]
    [ , , , ]
    136
    VALUES!

    View Slide

  137. @bitcapulet
    [ , , , ]
    [ , , , ]
    137
    VALUES!

    View Slide

  138. @bitcapulet138
    FORMATS!

    View Slide

  139. @bitcapulet139
    values in deep
    structures too!

    View Slide

  140. @bitcapulet
    =
    140

    View Slide

  141. @bitcapulet
    >%{}
    Of course it equal
    sign! Everyone guess
    that! Why you use
    clipart in first
    place?
    141

    View Slide

  142. @bitcapulet
    {:ok, "Jean-Luc Picard"} =
    get_fav_capt(human)
    142

    View Slide

  143. @bitcapulet
    {:ok, "Jean-Luc Picard"} =
    get_fav_capt(human)
    143

    View Slide

  144. @bitcapulet
    cookie = "delicious"
    144

    View Slide

  145. @bitcapulet
    cookie = "delicious"
    %{}
    Okay. This me
    can get behind.
    145

    View Slide

  146. @bitcapulet
    case 2 + 2
    4 -> "hurray"
    3 -> "oops"
    end
    146

    View Slide

  147. @bitcapulet
    case do_math(2)
    4 -> "hurray"
    3 -> "oops"
    end
    147

    View Slide

  148. @bitcapulet
    case do_math(2)
    4 -> "hurray"
    3 -> "oops"
    var -> "Got number: #{var}"
    end
    148

    View Slide

  149. @bitcapulet
    case do_math(2)
    4 -> "hurray"
    3 -> "oops"
    var -> "Got number: #{var}"
    end
    149

    View Slide

  150. @bitcapulet
    case do_math(2)
    4 -> "hurray"
    3 -> "oops"
    var -> "Got number: #{var}"
    [1, 2, 3] -> "123 list"
    end
    150

    View Slide

  151. @bitcapulet
    case do_math(2)
    4 -> "hurray"
    3 -> "oops"
    var -> "got number: #{var}"
    [1, 2, 3] -> "123 list"
    end
    151

    View Slide

  152. @bitcapulet
    case do_math(2)
    4 -> "hurray"
    3 -> "oops"
    var -> "got number: #{var}"
    [1, 2, 3] -> "123 list"
    end
    [ , , , ]
    1 2 3
    152

    View Slide

  153. @bitcapulet
    case do_math(2)
    4 -> "hurray"
    3 -> "oops"
    var -> "got number: #{var}"
    [1, 2, 3] -> "123 list"
    end
    [ , , , ]
    1 2 3
    153

    View Slide

  154. @bitcapulet
    case do_math(2)
    4 -> "hurray"
    3 -> "oops"
    var -> "got number: #{var}"
    [1, 2, 3] -> "123 list"
    end
    [ , , , ]
    1 2 3
    154

    View Slide

  155. @bitcapulet
    case do_math(2)
    4 -> "hurray"
    3 -> "oops"
    var -> "got number: #{var}"
    [1, 2, 3] -> "123 list"
    end
    155

    View Slide

  156. @bitcapulet
    case
    4 -> "hurray"
    3 -> "oops"
    var -> "got number: #{var}"
    [1, 2, 3] -> "123 list"
    end
    156

    View Slide

  157. @bitcapulet
    case
    4 -> "hurray"
    3 -> "oops"
    var -> "got number: #{var}"
    [1, 2, 3] -> "123 list"
    end
    157

    View Slide

  158. @bitcapulet
    case
    4 -> "hurray"
    3 -> "oops"
    var -> "got number: #{var}"
    [1, 2, 3] -> "123 list"
    end
    158

    View Slide

  159. @bitcapulet
    case
    4 -> "hurray"
    3 -> "oops"
    var -> "got number: #{var}"
    [1, 2, 3] -> "123 list"
    end
    159

    View Slide

  160. @bitcapulet
    case
    4 -> "hurray"
    3 -> "oops"
    var -> "got number: #{var}"
    [1, 2, 3] -> "123 list"
    end
    160

    View Slide

  161. @bitcapulet
    case
    4 -> "hurray"
    3 -> "oops"
    var -> "got number: #{var}"
    [1, 2, 3] -> "123 list"
    end
    161

    View Slide

  162. @bitcapulet
    case
    4 -> "hurray"
    3 -> "oops"
    var -> "got number: #{var}"
    [1, 2, 3] -> "123 list"
    end
    162

    View Slide

  163. @bitcapulet
    case
    4 -> "hurray"
    3 -> "oops"
    var -> "got number: #{var}"
    [1, 2, 3] -> "123 list"
    end
    163

    View Slide

  164. @bitcapulet
    case
    4 -> "hurray"
    3 -> "oops"
    var -> "got number: #{var}"
    [1, 2, 3] -> "123 list"
    end
    164

    View Slide

  165. @bitcapulet
    case
    4 -> "hurray"
    3 -> "oops"
    var ->
    [1, 2, 3] -> "123 list"
    end
    165

    View Slide

  166. @bitcapulet
    case
    4 -> "hurray"
    3 -> "oops"
    var ->
    [1, 2, 3] -> "123 list"
    end
    166

    View Slide

  167. @bitcapulet
    case
    4 -> "hurray"
    3 -> "oops"
    var ->
    [1, 2, 3] -> "123 list"
    end
    167

    View Slide

  168. @bitcapulet
    case
    4 -> "hurray"
    3 -> "oops"
    var ->
    [1, 2, 3] -> "123 list"
    end
    168

    View Slide

  169. @bitcapulet
    case
    4 -> "hurray"
    3 -> "oops"
    var ->
    [1, 2, 3] -> "123 list"
    end
    169

    View Slide

  170. @bitcapulet
    case
    4 -> "hurray"
    3 -> "oops"
    var ->
    [1, 2, 3] -> "123 list"
    end
    170

    View Slide

  171. @bitcapulet
    case do_math(2)
    4 -> "hurray"
    3 -> "oops"
    var -> "got number: #{var}"
    [1, 2, 3] -> "123 list"
    end
    171

    View Slide

  172. @bitcapulet
    case do_math(2)
    4 -> "hurray"
    3 -> "oops"
    var -> "got number: #{var}"
    [1, 2, 3] -> "123 list"
    end
    172

    View Slide

  173. @bitcapulet
    case do_math(2)
    4 -> "hurray"
    3 -> "oops"
    [1, 2, 3] -> "123 list"
    var -> "got number: #{var}"
    end
    173

    View Slide

  174. @bitcapulet
    case do_math(2)
    4 -> "hurray"
    3 -> "oops"
    [1, 2, 3] -> "123 list"
    var -> "got number: #{var}"
    end
    174

    View Slide

  175. @bitcapulet
    %{}
    That long section.
    175

    View Slide

  176. @bitcapulet
    %{}
    That long section.
    Me need break.
    176

    View Slide

  177. @bitcapulet177

    View Slide

  178. @bitcapulet178

    View Slide

  179. @bitcapulet179

    View Slide

  180. @bitcapulet180

    View Slide

  181. @bitcapulet181

    View Slide

  182. @bitcapulet
    Beam
    Processes
    Steal from telephony.
    182

    View Slide

  183. @bitcapulet183

    View Slide

  184. @bitcapulet184

    View Slide

  185. @bitcapulet185

    View Slide

  186. @bitcapulet186

    View Slide

  187. @bitcapulet187

    View Slide

  188. @bitcapulet188

    View Slide

  189. @bitcapulet189

    View Slide

  190. @bitcapulet190

    View Slide

  191. @bitcapulet191

    View Slide

  192. @bitcapulet192

    View Slide

  193. @bitcapulet193

    View Slide

  194. @bitcapulet
    134 Million Processes
    194

    View Slide

  195. @bitcapulet
    134 Million Processes
    195

    View Slide

  196. @bitcapulet
    134 Million Processes
    196

    View Slide

  197. @bitcapulet
    134 Million Processes
    197

    View Slide

  198. @bitcapulet
    134 Million Processes
    198

    View Slide

  199. @bitcapulet
    134 Million Processes
    199

    View Slide

  200. @bitcapulet
    134 Million Processes
    200

    View Slide

  201. @bitcapulet
    134 Million Processes
    201

    View Slide

  202. @bitcapulet
    134 Million Processes
    202

    View Slide

  203. @bitcapulet
    134 Million Processes
    203

    View Slide

  204. @bitcapulet
    defmodule MyModule
    def phil(state) do
    phil(state + 1)
    end
    end
    204

    View Slide

  205. @bitcapulet
    defmodule MyModule
    def phil(state) do
    receive do
    value ->
    IO.puts("count: " <> state)
    IO.puts("Phil got: " <> value)
    end
    phil(state + 1)
    end
    end
    205

    View Slide

  206. @bitcapulet
    Interactive Elixir (1.6.1) - press Ctrl+C to exit (type h()
    ENTER for help)
    iex(1)>
    206

    View Slide

  207. @bitcapulet
    Interactive Elixir (1.6.1) - press Ctrl+C to exit (type h()
    ENTER for help)
    iex(1)> IO.puts("Hello, world!")
    Hello, world!
    :ok
    iex(2)>
    207

    View Slide

  208. @bitcapulet
    iex(2)> pid = spawn(MyModule, :phil, 0)
    #PID<0.97.0>
    iex(3)>
    208

    View Slide

  209. @bitcapulet
    iex(2)> pid = spawn(MyModule, :phil, 0)
    #PID<0.97.0>
    iex(3)> Process.alive?(pid)
    true
    iex(4)>
    209

    View Slide

  210. @bitcapulet
    iex(2)> pid = spawn(MyModule, :phil, 0)
    #PID<0.97.0>
    iex(3)> Process.alive?(pid)
    true
    iex(4)> send(pid, "hello")
    count: 0
    Phil got: hello
    "hello"
    iex(5)>
    210

    View Slide

  211. @bitcapulet
    iex(2)> pid = spawn(MyModule, :phil, 0)
    #PID<0.97.0>
    iex(3)> Process.alive?(pid)
    true
    iex(4)> send(pid, "hello")
    count: 0
    Phil got: hello
    "hello"
    iex(5)> send(pid, "hello")
    count: 1
    Phil got: hello
    "hello"
    211

    View Slide

  212. @bitcapulet
    spawn
    receive
    send
    212
    Built right into the
    language!

    View Slide

  213. @bitcapulet
    A process is a recursive function that holds state
    and lives at an address with a mailbox.
    <0.194.0>
    213

    View Slide

  214. @bitcapulet
    >%{}
    We back in OO-land!
    214

    View Slide

  215. @bitcapulet
    >%{}
    We back in OO-land!
    How this not just
    uglier-Java?!
    215

    View Slide

  216. @bitcapulet216

    View Slide

  217. @bitcapulet
    x x
    217

    View Slide

  218. @bitcapulet
    x x
    x x
    x x
    x x
    x x
    x x
    x x
    218

    View Slide

  219. @bitcapulet219

    View Slide

  220. @bitcapulet220

    View Slide

  221. @bitcapulet221

    View Slide

  222. @bitcapulet222

    View Slide

  223. @bitcapulet223

    View Slide

  224. @bitcapulet224

    View Slide

  225. @bitcapulet
    225

    View Slide

  226. @bitcapulet
    226

    View Slide

  227. @bitcapulet
    227

    View Slide

  228. @bitcapulet
    228

    View Slide

  229. @bitcapulet
    229

    View Slide

  230. @bitcapulet
    230

    View Slide

  231. @bitcapulet
    231

    View Slide

  232. @bitcapulet
    %{}
    Break time
    232

    View Slide

  233. @bitcapulet233

    View Slide

  234. @bitcapulet234

    View Slide

  235. @bitcapulet235

    View Slide

  236. @bitcapulet236

    View Slide

  237. @bitcapulet237

    View Slide

  238. @bitcapulet
    Function
    Signatures
    State complexity clearly.
    238

    View Slide

  239. @bitcapulet
    def run(a,b,c,d) do
    [d,c,b,a]
    end
    239

    View Slide

  240. @bitcapulet
    def run(a,b,c,d) do
    [d,c,b,a]
    end
    240
    Uneven

    View Slide

  241. @bitcapulet
    def run(list) do
    [a,b,c,d] = list
    [d,c,b,a]
    end
    241

    View Slide

  242. @bitcapulet
    def run(list) do
    [a,b,c,d] = list
    [d,c,b,a]
    end
    242
    What if > 4 items?

    View Slide

  243. @bitcapulet
    run([1,2,3,4,5])
    ** (MatchError) no match of right
    hand side value: [1, 2, 3, 4, 5]
    243

    View Slide

  244. @bitcapulet
    def run(list) do
    [a,b,c,d] = list
    [d,c,b,a]
    end
    244
    object?

    View Slide

  245. @bitcapulet
    {tuple}
    245

    View Slide

  246. @bitcapulet
    quartet = {1,2,3,4}
    trio = {"one", 2, %{}}
    246

    View Slide

  247. @bitcapulet
    def run(tuple) do
    {a,b,c,d} = tuple
    {d,c,b,a}
    end
    247

    View Slide

  248. @bitcapulet
    def run(tuple) do
    {a,b,c,d} = tuple
    {d,c,b,a}
    end
    248

    View Slide

  249. @bitcapulet
    def run({a,b,c,d}) do
    {d,c,b,a}
    end
    249

    View Slide

  250. @bitcapulet
    def run(tuple = {a,b,c,d}) do
    IO.inspect(tuple)
    {d,c,b,a}
    end
    250

    View Slide

  251. @bitcapulet
    def run(tuple = {a,b,c,d}) do
    IO.inspect(tuple)
    {d,c,b,a}
    end
    251
    Now reverse 5!

    View Slide

  252. @bitcapulet
    def run(tuple = {a,b,c,d}) do
    IO.inspect(tuple)
    {d,c,b,a}
    end
    def run(tuple = {a,b,c,d,e}) do
    IO.inspect(tuple)
    {e,d,c,b,a}
    end
    252

    View Slide

  253. @bitcapulet
    def run(tuple = {a,b,c,d}) do
    IO.inspect(tuple)
    {d,c,b,a}
    end
    def run(tuple = {a,b,c,d,e}) do
    IO.inspect(tuple)
    {e,d,c,b,a}
    end
    253

    View Slide

  254. @bitcapulet
    def run(tuple = {a,b,c,d}) do
    IO.inspect(tuple)
    {d,c,b,a}
    end
    def run(tuple = {a,b,c,d,e}) do
    IO.inspect(tuple)
    {e,d,c,b,a}
    end
    254

    View Slide

  255. @bitcapulet
    def run(tuple = {a,b,c,d}) do
    IO.inspect(tuple)
    {d,c,b,a}
    end
    def run(tuple = {a,b,c,d,e}) do
    IO.inspect(tuple)
    {e,d,c,b,a}
    end
    255

    View Slide

  256. @bitcapulet
    def run(tuple = {a,b,c,d}) do
    IO.inspect(tuple)
    {d,c,b,a}
    end
    def run(tuple = {a,b,c,d,e}) do
    IO.inspect(tuple)
    {e,d,c,b,a}
    end
    256

    View Slide

  257. @bitcapulet
    def run(tuple = {a,b,c,d}) do
    IO.inspect(tuple)
    {d,c,b,a}
    end
    def run(tuple = {a,b,c,d,e}) do
    IO.inspect(tuple)
    {e,d,c,b,a}
    end
    257

    View Slide

  258. @bitcapulet
    def run(tuple = {a,b,c,d}) do
    IO.inspect(tuple)
    {d,c,b,a}
    end
    def run(tuple = {a,b,c,d,e}) do
    IO.inspect(tuple)
    {e,d,c,b,a}
    end
    258

    View Slide

  259. @bitcapulet
    This is why Java
    has factories!
    259

    View Slide

  260. @bitcapulet
    GenServer
    Steal from telephony.
    260

    View Slide

  261. @bitcapulet
    A process is a recursive function that holds state
    and lives at an address with a mailbox.
    <0.194.0>
    261

    View Slide

  262. @bitcapulet
    A GenServer is like a
    Starfleet officer
    262

    View Slide

  263. @bitcapulet
    defmodule Phil do
    IO.puts("Phil got: " <> value)
    end
    263

    View Slide

  264. @bitcapulet
    defmodule Phil do
    use GenServer
    def init(_args), do: 0
    def handle_cast(value, from, state) do
    IO.puts("Phil got: " <> value)
    {:noreply, state + 1}
    end
    end
    264

    View Slide

  265. @bitcapulet
    defmodule Phil do
    use GenServer
    def init(_args), do: 0
    def handle_cast(value, from, state) do
    IO.puts("Phil got: " <> value)
    {:noreply, state + 1}
    end
    end
    265

    View Slide

  266. @bitcapulet
    defmodule Phil do
    use GenServer
    def init(_args), do: 0
    def handle_cast(value, from, state) do
    IO.puts("Phil got: " <> value)
    {:noreply, state + 1}
    end
    end
    266

    View Slide

  267. @bitcapulet
    defmodule Phil do
    use GenServer
    def init(_args), do: 0
    def handle_cast(value, from, state) do
    IO.puts("Phil got: " <> value)
    {:noreply, state + 1}
    end
    end
    267

    View Slide

  268. @bitcapulet
    defmodule Phil do
    use GenServer
    def init(_args), do: 0
    def handle_cast(value, from, state) do
    IO.puts("Phil got: " <> value)
    {:noreply, state + 1}
    end
    def handle_call(:say_something, from, state) do
    {:reply, "something", state}
    end
    end
    268

    View Slide

  269. @bitcapulet
    {:ok, pid} = GenServer.start_link(Phil, "arg")
    def init(_args), do: 0
    Spawn a GenServer
    269

    View Slide

  270. @bitcapulet
    Asynchronous
    requests
    def handle_cast(value, from, state) do
    IO.puts("Phil got: " <> value)
    {:noreply, state + 1}
    end
    GenServer.cast(pid, "a present")
    move_right_along()
    270

    View Slide

  271. @bitcapulet
    def handle_call(:say_something, from, state) do
    IO.puts("Phil got: " <> value)
    {:reply, "Thanks", state}
    end
    Synchronous
    requests
    reply = GenServer.call(pid, :say_something)
    271

    View Slide

  272. @bitcapulet
    Synchronous
    requests
    reply = GenServer.call(pid, :say_something)
    272
    PID passing gets old

    View Slide

  273. @bitcapulet
    GenServer.start_link(Phil, "arg", name: :phil)
    Fee pid Registry
    273

    View Slide

  274. @bitcapulet
    GenServer.start_link(Phil, "arg", name: :phil)
    GenServer.cast(:phil, "a present with your name on it")
    Fee pid Registry
    274

    View Slide

  275. @bitcapulet
    GenServer.start_link(Phil, "arg", name: :phil)
    GenServer.cast(:phil, "a present with your name on it")
    pid = Process.whereis(:phil)
    Fee pid Registry
    275

    View Slide

  276. @bitcapulet
    Supervisors
    276

    View Slide

  277. @bitcapulet
    Supervisors
    277

    View Slide

  278. @bitcapulet
    defmodule CaptJoan do
    use Supervisor
    def init(_args) do
    children = [
    {Phil, []}
    ]
    Supervisor.init(children, strategy: :one_for_one)
    end
    end
    278

    View Slide

  279. @bitcapulet
    defmodule CaptJoan do
    use Supervisor
    def init(_args) do
    children = [
    {Phil, []}
    ]
    Supervisor.init(children, strategy: :one_for_one)
    end
    end
    279

    View Slide

  280. @bitcapulet
    defmodule CaptJoan do
    use Supervisor
    def init(_args) do
    children = [
    {Phil, []}
    ]
    Supervisor.init(children, strategy: :one_for_one)
    end
    end
    280

    View Slide

  281. @bitcapulet
    defmodule CaptJoan do
    use Supervisor
    def init(_args) do
    children = [
    {Phil, []},
    {Phil, []},
    {Phil, []}
    ]
    Supervisor.init(children, strategy: :one_for_one)
    end
    end
    281

    View Slide

  282. @bitcapulet
    defmodule CaptJoan do
    use Supervisor
    def init(_args) do
    children = [
    {Phil, []},
    {Phil, []},
    {Phil, []}
    ]
    Supervisor.init(children, strategy: :one_for_one)
    end
    end
    282

    View Slide

  283. @bitcapulet
    283

    View Slide

  284. @bitcapulet
    284

    View Slide

  285. @bitcapulet
    285

    View Slide

  286. @bitcapulet
    defmodule CaptJoan do
    use Supervisor
    def init(_args) do
    children = [
    {Phil, []},
    {Phil, []},
    {Phil, ["arg"]}
    ]
    Supervisor.init(children, strategy: :one_for_one)
    end
    end
    286

    View Slide

  287. @bitcapulet
    defmodule CaptJoan do
    use Supervisor
    def init(_args) do
    children = [
    {Phil, []},
    {Phil, []},
    {Phil, ["arg"]}
    ]
    Supervisor.init(children, strategy: :one_for_all)
    end
    end
    287

    View Slide

  288. @bitcapulet
    defmodule AdmiralRavi do
    use Supervisor
    def init(_args) do
    children = [
    {CaptJoan, []},
    {CaptJoan, []},
    {CaptJoan, []}
    ]
    Supervisor.init(children, strategy: :one_for_one)
    end
    end
    288

    View Slide

  289. @bitcapulet289

    View Slide

  290. @bitcapulet290

    View Slide

  291. @bitcapulet291

    View Slide

  292. @bitcapulet292

    View Slide

  293. @bitcapulet293

    View Slide

  294. @bitcapulet294

    View Slide

  295. @bitcapulet295

    View Slide

  296. @bitcapulet296

    View Slide

  297. @bitcapulet297

    View Slide

  298. @bitcapulet298

    View Slide

  299. @bitcapulet299

    View Slide

  300. @bitcapulet300

    View Slide

  301. @bitcapulet301

    View Slide

  302. @bitcapulet302

    View Slide

  303. @bitcapulet303

    View Slide

  304. @bitcapulet
    #PID<0.96.0>
    <0.194.0>
    304

    View Slide

  305. @bitcapulet305
    send(pid, "hello")
    GenServer.cast(:phil, "a present with your name on it")

    View Slide

  306. @bitcapulet
    ◍ timeouts
    ◍ linking processes
    ◌ monitoring
    ◌ trapping exits
    ◍ error handling
    Other benefits
    306

    View Slide

  307. @bitcapulet
    defmodule AdmiralRavi do
    use Supervisor
    def init(_args) do
    children = [
    {CaptJoan, []},
    {CaptJoan, []},
    {CaptJoan, []}
    ]
    Supervisor.init(children, strategy: :one_for_one)
    end
    end
    307

    View Slide

  308. @bitcapulet
    %{}
    ME WANT MORE
    BREAK!
    308

    View Slide

  309. @bitcapulet

    View Slide

  310. @bitcapulet

    View Slide

  311. @bitcapulet

    View Slide

  312. @bitcapulet

    View Slide

  313. @bitcapulet

    View Slide

  314. @bitcapulet
    Function
    Pipeline
    State complexity clearly
    314

    View Slide

  315. @bitcapulet
    def fav_capt(:kirk) do
    {:error, "Are you kidding me?"}
    end
    def fav_capt(:picard) do
    {:ok, "You chose wisely."}
    end
    315

    View Slide

  316. @bitcapulet
    capt = :picard
    {:ok, message} = fav_capt(capt)
    IO.puts(message)
    316

    View Slide

  317. @bitcapulet
    capt = :kirk
    {:ok, message} = fav_capt(capt)
    IO.puts(message)
    ** (MatchError) no match of right hand
    side value: {:error, "Are you kidding
    me?"}
    317

    View Slide

  318. @bitcapulet
    capt = :kirk
    case fav_capt(capt)
    {:ok, msg} -> msg
    {:error, msg} -> Log.error("oops")
    end
    318

    View Slide

  319. @bitcapulet
    capt = :kirk
    case fav_capt(capt)
    {:ok, msg} -> msg
    {:error, _msg} -> Log.error("oops")
    end
    319

    View Slide

  320. @bitcapulet
    capt = :kirk
    case fav_capt(capt)
    {:ok, msg} -> msg
    {:error, _msg} -> Log.error("oops")
    {_, _msg} -> Log.error("What?!")
    end
    320

    View Slide

  321. @bitcapulet
    capt = :kirk
    case fav_capt(capt)
    {:ok, msg} -> msg
    {:error, _msg} -> Log.error("oops")
    {_, _msg} -> Log.error("What?!")
    _ -> Log.error("Oh dear.")
    end
    321

    View Slide

  322. @bitcapulet
    case fav_capt(capt)
    {:ok, msg} ->
    Log.info("That went well.")
    msg
    {:error, _msg} -> Log.error("oops")
    {_, _msg} -> Log.error("What?!")
    _ -> Log.error("Oh dear.")
    end
    322

    View Slide

  323. @bitcapulet
    def respond({:ok, msg}) do
    Log.info("That went well.")
    msg
    end
    def respond({:error, _msg}) do
    Log.error("oops")
    end
    323

    View Slide

  324. @bitcapulet
    respond(fav_capt(capt))
    324

    View Slide

  325. @bitcapulet
    respond(fav_capt(capt))
    capt
    |> fav_capt()
    |> respond()
    325

    View Slide

  326. @bitcapulet326

    View Slide

  327. @bitcapulet
    capt
    |> fav_capt()
    |> respond()
    327

    View Slide

  328. @bitcapulet
    capt.fav_capt().respond()
    // This is constrained.
    328

    View Slide

  329. @bitcapulet
    capt
    |> fav_capt()
    |> respond()
    329

    View Slide

  330. @bitcapulet
    capt
    |>
    330

    View Slide

  331. @bitcapulet
    capt
    |> beam_to_planet()
    331

    View Slide

  332. @bitcapulet
    capt
    |> beam_to_planet()
    |> meet_aliens()
    332

    View Slide

  333. @bitcapulet
    capt
    |> beam_to_planet()
    |> meet_aliens()
    |> romance?()
    333

    View Slide

  334. @bitcapulet
    capt
    |> beam_to_planet()
    |> meet_aliens()
    |> romance?()
    |> case do
    {:ok, details} -> log(details)
    :error -> kill_off_extra()
    end
    334

    View Slide

  335. @bitcapulet
    capt
    |> beam_to_planet()
    |> meet_aliens()
    |> romance?()
    |> case do
    {:ok, details} -> log(details)
    :error -> kill_off_extra()
    end
    335

    View Slide

  336. @bitcapulet
    capt
    |> beam_to_planet()
    |> meet_aliens()
    |> romance?()
    |> case do
    {:ok, details} -> log(details)
    :error -> kill_off_extra()
    end
    336

    View Slide

  337. @bitcapulet
    [1, 2, 3]
    337

    View Slide

  338. @bitcapulet
    [1, 2, 3]
    |> Enum.map(fn i -> i + 1 end)
    # [2, 3, 4]
    338

    View Slide

  339. @bitcapulet
    [1, 2, 3]
    |> Enum.map(fn i -> i + 1 end)
    |> Enum.sum()
    # 9
    339

    View Slide

  340. @bitcapulet
    %{}
    It late. Wrap
    it up.
    340

    View Slide

  341. @bitcapulet341
    GenServer.start_link(CircleKeeper,[], name: :circle_keeper)
    GenServer.cast(:circle_keeper, {:add, %Circle{radius: 3})
    total_area = GenServer.call(:circle_keeper, :total_area)

    View Slide

  342. @bitcapulet
    defmodule CircleKeeper do
    use GenServer
    def init(starting_circles), do: starting_circles
    def handle_cast({:add, circle}, _, circles),
    do: {:noreply, circles ++ circle}
    def handle_call(:total_area, circles),
    do: {:reply, sum_radii(circles), circles}
    defp sum_radii(circles) do
    circles
    |> Enum.map(fn c -> Circle.area(c.radius) end)
    |> Enum.sum()
    end
    end
    342

    View Slide

  343. @bitcapulet
    {}
    343

    View Slide

  344. @bitcapulet
    %{}
    344

    View Slide

  345. @bitcapulet
    %{}
    345

    View Slide

  346. @bitcapulet
    %{}
    346

    View Slide

  347. @bitcapulet
    %{}
    Me here to say
    something inspiring
    to end talk.
    347

    View Slide

  348. @bitcapulet
    %{}
    Language not really
    most important
    thing.
    348

    View Slide

  349. @bitcapulet
    %{}
    It matter you do job.
    349

    View Slide

  350. @bitcapulet
    %{}
    It matter you do job.
    And you happy with
    job you do.
    350

    View Slide

  351. @bitcapulet
    %{}
    It also matter you
    make lots of money.
    351

    View Slide

  352. @bitcapulet
    %{}
    This language not
    make more money.
    352

    View Slide

  353. @bitcapulet
    %{}
    This language not
    make more money.
    But maybe make
    more happy.
    353

    View Slide

  354. @bitcapulet
    %{}
    Adrian happy.
    354

    View Slide

  355. @bitcapulet
    %{}
    Adrian happy.
    He crazy.
    355

    View Slide

  356. @bitcapulet
    %{}
    Adrian happy.
    He crazy.
    But he happy.
    356

    View Slide

  357. @bitcapulet
    %{}
    He right about Elixir.
    It great.
    357

    View Slide

  358. @bitcapulet
    %{}
    Me hope you friends
    try it out.
    358

    View Slide

  359. @bitcapulet
    %{}
    359

    View Slide

  360. @bitcapulet
    %{}
    You know how you
    thank me.
    360

    View Slide

  361. @bitcapulet
    %{ }
    361

    View Slide

  362. @bitcapulet
    %{0}
    362

    View Slide

  363. @bitcapulet
    %{}
    363

    View Slide

  364. @bitcapulet
    %{*}
    364

    View Slide

  365. @bitcapulet
    %{}
    365

    View Slide

  366. @bitcapulet
    %{.}
    366

    View Slide

  367. @bitcapulet
    %{}
    367

    View Slide

  368. @bitcapulet
    %{}
    Bye!
    368

    View Slide

  369. @bitcapulet
    %{}
    369

    View Slide

  370. @bitcapulet
    %{}
    370

    View Slide

  371. @bitcapulet
    %{}
    371

    View Slide

  372. @bitcapulet
    %{}
    372

    View Slide

  373. @bitcapulet
    %{}
    373

    View Slide

  374. @bitcapulet
    %{}
    374

    View Slide

  375. @bitcapulet375

    View Slide

  376. @bitcapulet
    Pinball
    Elixir
    Presentation template by SlidesCarnival
    376
    Adrian P. Dunston
    @bitcapulet
    [email protected]
    joinpapa.com

    View Slide