Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Pinball Elixir
Search
Adrian Dunston
October 14, 2019
Technology
0
43
Pinball Elixir
Intro to Elixir with Pinball
Adrian Dunston
October 14, 2019
Tweet
Share
More Decks by Adrian Dunston
See All by Adrian Dunston
The Deal: QA and Dev Together (Triagile 2021)
apdunston
0
36
The Annotated Meeting - An Exciting New Tool for Leading Dialogue and Building Consensus (Triagile 2021)
apdunston
1
54
Tester at the Table and the Tester in my Head (Abstractions 2019)
apdunston
0
23
The Deal: Quality and Development Together
apdunston
0
150
The Tester at the Table and the Tester in my Head
apdunston
0
110
Other Decks in Technology
See All in Technology
100 名超が参加した日経グループ横断の競技型 AWS 学習イベント「Nikkei Group AWS GameDay」の紹介/mediajaws202411
nikkei_engineer_recruiting
1
170
エンジニア人生の拡張性を高める 「探索型キャリア設計」の提案
tenshoku_draft
1
130
OCI Security サービス 概要
oracle4engineer
PRO
0
6.5k
アジャイルでの品質の進化 Agile in Motion vol.1/20241118 Hiroyuki Sato
shift_evolve
0
170
B2B SaaSから見た最近のC#/.NETの進化
sansantech
PRO
0
900
EventHub Startup CTO of the year 2024 ピッチ資料
eventhub
0
120
生成AIが変えるデータ分析の全体像
ishikawa_satoru
0
170
IBC 2024 動画技術関連レポート / IBC 2024 Report
cyberagentdevelopers
PRO
1
110
インフラとバックエンドとフロントエンドをくまなく調べて遅いアプリを早くした件
tubone24
1
430
TanStack Routerに移行するのかい しないのかい、どっちなんだい! / Are you going to migrate to TanStack Router or not? Which one is it?
kaminashi
0
600
SRE×AIOpsを始めよう!GuardDutyによるお手軽脅威検出
amixedcolor
0
180
AWS Media Services 最新サービスアップデート 2024
eijikominami
0
200
Featured
See All Featured
Code Reviewing Like a Champion
maltzj
520
39k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
47
2.1k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
28
2k
Ruby is Unlike a Banana
tanoku
97
11k
Building Adaptive Systems
keathley
38
2.3k
What's in a price? How to price your products and services
michaelherold
243
12k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
GitHub's CSS Performance
jonrohan
1030
460k
Transcript
Pinball Elixir with Adrian P. Dunston
@bitcapulet Purpose To get you excited about Elixir. 2
@bitcapulet Purpose To get you excited about Elixir. So you’ll
be more powerful. 3
@bitcapulet Purpose To get you excited about Elixir. So you’ll
be more powerful. So your companies will start using it. 4
@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
@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
@bitcapulet Story Time! 7
@bitcapulet Story Time! Kevin McAbee 8
@bitcapulet
@bitcapulet
@bitcapulet
@bitcapulet Story Time! Kevin McAbee 12
@bitcapulet13
@bitcapulet14
@bitcapulet15
@bitcapulet16
Adrian P. Dunston
[email protected]
@bitcapulet 17 joinpapa.com
18 Adrian P. Dunston
[email protected]
@bitcapulet 18 joinpapa.com
@bitcapulet What is essential? 19
@bitcapulet State complexity clearly. Steal from telephony. 20
@bitcapulet Elixir does two things very well. 21
@bitcapulet If you state your complexity clearly, it's easier to
solve complex problems. 22
@bitcapulet If you state your complexity clearly, it's easier to
solve complex problems. Distributed systems = complex problems 23
@bitcapulet If you state your complexity clearly, it's easier to
solve complex problems. Functional programming forces this. 24
@bitcapulet If you state your complexity clearly, it's easier to
solve complex problems. This is what ELIXIR brings to the table. 25
@bitcapulet Rob those phone companies blind! 26
@bitcapulet Rob those phone companies blind! 16 years of searching
and building. 27
@bitcapulet Rob those phone companies blind! 16 years of searching
and building. THEN 20 years of open-source improvements. 28
@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!
@bitcapulet State complexity clearly. 30
@bitcapulet State complexity clearly. Steal from telephony. 31
@bitcapulet Magic Matching State complexity clearly. 32
@bitcapulet33
@bitcapulet34
@bitcapulet35
@bitcapulet36
@bitcapulet37
@bitcapulet38
@bitcapulet39
@bitcapulet40
@bitcapulet41
@bitcapulet42
@bitcapulet 42 43
@bitcapulet 'a' 44
@bitcapulet [1,2] 45
@bitcapulet :ok 46
@bitcapulet :ok ? 47
@bitcapulet :ok :oj :ol 48
@bitcapulet :ok :oj :ol :error :erroq :erros :adrian :adriam :adriao
49
@bitcapulet50
@bitcapulet51
@bitcapulet Plunger 52
@bitcapulet Plunger 53
@bitcapulet Plunger Playfield 54
@bitcapulet Plunger Playfield 55
@bitcapulet Plunger Playfield 56
@bitcapulet Plunger Playfield Drain 57
@bitcapulet Plunger Playfield Drain 58
@bitcapulet def run(ball) do ball end 59
@bitcapulet def run(ball) do ball; end 60
@bitcapulet def run(ball) do return ball; end 61
@bitcapulet def run(ball) do ball end Drain 62
@bitcapulet63
@bitcapulet64
@bitcapulet65
@bitcapulet66
@bitcapulet def run(a,b,c,d) do # ummm... end 67
@bitcapulet def run(a,b,c,d) do [d,c,b,a] end 68
@bitcapulet69
@bitcapulet def run(a,b,c,d) do [d,c,b,a] end 70
@bitcapulet71
@bitcapulet72
@bitcapulet73
@bitcapulet [ , , , ] 74
@bitcapulet [ , , , ] a b c d
75
@bitcapulet [ , , , ] a b c d
def get_odd(list) do a = Enum.at(list, 0) c = Enum.at(list, 2) [a, c] end 76
@bitcapulet77
@bitcapulet [a, b, c, d] [ , , , ]
78
@bitcapulet [ , , , ] [ , , ,
] 79
@bitcapulet [ , , , ] [ , , ,
] 80
@bitcapulet [ , , , ] [ , , ,
] 81
@bitcapulet [ , , , ] [ , , ,
] 82
@bitcapulet [ , , , ] a b c d
def get_odd(list) do a = Enum.at(list, 0) c = Enum.at(list, 2) [a, c] end 83
@bitcapulet [ , , , ] a b c d
def get_odd(list) do [a, b, c, d] list [a, c] end 84
@bitcapulet [ , , , ] a b c d
def get_odd(list) do [a, _, c, _] list [a, c] end 85
@bitcapulet [ , , , ] a b c d
def get_odd(list) do [a, _b, c, _d] list [a, c] end 86
@bitcapulet Captive Ball 87
@bitcapulet Multiball!! 88
@bitcapulet Kicker 89
@bitcapulet90
@bitcapulet91
@bitcapulet %{name: "Adrian"} 92
@bitcapulet %{name: "Adrian"} jsObject = {"name": "Adrian"} 93
@bitcapulet Map<Integer,String> map = new HashMap<Integer,String>(); map.put("name","Adrian"); 94
@bitcapulet %{name: "Adrian"} 95
@bitcapulet %{ name: "Adrian", age: 40, fav_capt: "Picard" } 96
@bitcapulet human = %{ name: "Adrian", age: 40, fav_capt: "Picard"
} 97
@bitcapulet human = %{ name: "Adrian", age: 40, fav_capt: "Picard"
} 98
@bitcapulet human = %{ name: , age: , fav_capt: }
99
@bitcapulet human 100
@bitcapulet %{name: var} human 101
@bitcapulet %{name: var} human 102
@bitcapulet %{name: var} human 103
@bitcapulet %{name: var} human 104
@bitcapulet %{name: var} "Adrian" human 105
@bitcapulet def get_name(map) do %{name: var} map var end 106
@bitcapulet def get_name(map) do %{name: var} map var end get_name(%{})
107
@bitcapulet get_name(%{}) 108
@bitcapulet get_name(%{}) %{} 109
@bitcapulet %{} Cookie Monster CONFIRMED!! 110
@bitcapulet %{ } Cookie Monster CONFIRMED!! 111
@bitcapulet %{0} Cookie Monster CONFIRMED!! 112
@bitcapulet %{} Cookie Monster CONFIRMED!! 113
@bitcapulet %{*} Cookie Monster CONFIRMED!! 114
@bitcapulet %{} Cookie Monster CONFIRMED!! 115
@bitcapulet %{.} Cookie Monster CONFIRMED!! 116
@bitcapulet %{} Cookie Monster CONFIRMED!! 117
@bitcapulet %{} Me love it! 118
@bitcapulet119
@bitcapulet def get_name(map) do %{name: var} map var end get_name(%{})
120
@bitcapulet def get_name(map) do %{name: var} map var end get_name(%{})
** (MatchError) no match of right hand side value: %{} 121
@bitcapulet %{} What you mean let process fail?! 122
@bitcapulet123
@bitcapulet124
@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!
@bitcapulet %{name: _, age: _, fav_capt: _ } my_map 126
@bitcapulet %{"name" => _, "age" => _, "fav.capt." => "Picard"
} my_map %{name: _, age: _, fav_capt: "Picard" } my_map 127
@bitcapulet128
@bitcapulet %{"name" => _, "age" => _, "fav.capt." => "Picard"
} my_map %{name: _, age: _, fav_capt: "Picard" } my_map 129
@bitcapulet %{"name" => _, "age" => _, "fav.capt." => "Picard"
} my_map [ %{fav_capt: "Kirk"}, %{fav_capt: "Picard"}, %{fav_capt: "Sisko"}, %{fav_capt: "Janeway"}, ] list_of_maps 130
@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
@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
@bitcapulet [ , , , ] [ , , ,
] 133 VALUES!
@bitcapulet [ , , , ] [ , , ,
] 134 VALUES!
@bitcapulet [ , , , ] [ , , ,
] 135 VALUES!
@bitcapulet [ , , , ] [ , , ,
] 136 VALUES!
@bitcapulet [ , , , ] [ , , ,
] 137 VALUES!
@bitcapulet138 FORMATS!
@bitcapulet139 values in deep structures too!
@bitcapulet = 140
@bitcapulet >%{} Of course it equal sign! Everyone guess that!
Why you use clipart in first place? 141
@bitcapulet {:ok, "Jean-Luc Picard"} = get_fav_capt(human) 142
@bitcapulet {:ok, "Jean-Luc Picard"} = get_fav_capt(human) 143
@bitcapulet cookie = "delicious" 144
@bitcapulet cookie = "delicious" %{} Okay. This me can get
behind. 145
@bitcapulet case 2 + 2 4 -> "hurray" 3 ->
"oops" end 146
@bitcapulet case do_math(2) 4 -> "hurray" 3 -> "oops" end
147
@bitcapulet case do_math(2) 4 -> "hurray" 3 -> "oops" var
-> "Got number: #{var}" end 148
@bitcapulet case do_math(2) 4 -> "hurray" 3 -> "oops" var
-> "Got number: #{var}" end 149
@bitcapulet case do_math(2) 4 -> "hurray" 3 -> "oops" var
-> "Got number: #{var}" [1, 2, 3] -> "123 list" end 150
@bitcapulet case do_math(2) 4 -> "hurray" 3 -> "oops" var
-> "got number: #{var}" [1, 2, 3] -> "123 list" end 151
@bitcapulet case do_math(2) 4 -> "hurray" 3 -> "oops" var
-> "got number: #{var}" [1, 2, 3] -> "123 list" end [ , , , ] 1 2 3 152
@bitcapulet case do_math(2) 4 -> "hurray" 3 -> "oops" var
-> "got number: #{var}" [1, 2, 3] -> "123 list" end [ , , , ] 1 2 3 153
@bitcapulet case do_math(2) 4 -> "hurray" 3 -> "oops" var
-> "got number: #{var}" [1, 2, 3] -> "123 list" end [ , , , ] 1 2 3 154
@bitcapulet case do_math(2) 4 -> "hurray" 3 -> "oops" var
-> "got number: #{var}" [1, 2, 3] -> "123 list" end 155
@bitcapulet case 4 -> "hurray" 3 -> "oops" var ->
"got number: #{var}" [1, 2, 3] -> "123 list" end 156
@bitcapulet case 4 -> "hurray" 3 -> "oops" var ->
"got number: #{var}" [1, 2, 3] -> "123 list" end 157
@bitcapulet case 4 -> "hurray" 3 -> "oops" var ->
"got number: #{var}" [1, 2, 3] -> "123 list" end 158
@bitcapulet case 4 -> "hurray" 3 -> "oops" var ->
"got number: #{var}" [1, 2, 3] -> "123 list" end 159
@bitcapulet case 4 -> "hurray" 3 -> "oops" var ->
"got number: #{var}" [1, 2, 3] -> "123 list" end 160
@bitcapulet case 4 -> "hurray" 3 -> "oops" var ->
"got number: #{var}" [1, 2, 3] -> "123 list" end 161
@bitcapulet case 4 -> "hurray" 3 -> "oops" var ->
"got number: #{var}" [1, 2, 3] -> "123 list" end 162
@bitcapulet case 4 -> "hurray" 3 -> "oops" var ->
"got number: #{var}" [1, 2, 3] -> "123 list" end 163
@bitcapulet case 4 -> "hurray" 3 -> "oops" var ->
"got number: #{var}" [1, 2, 3] -> "123 list" end 164
@bitcapulet case 4 -> "hurray" 3 -> "oops" var ->
[1, 2, 3] -> "123 list" end 165
@bitcapulet case 4 -> "hurray" 3 -> "oops" var ->
[1, 2, 3] -> "123 list" end 166
@bitcapulet case 4 -> "hurray" 3 -> "oops" var ->
[1, 2, 3] -> "123 list" end 167
@bitcapulet case 4 -> "hurray" 3 -> "oops" var ->
[1, 2, 3] -> "123 list" end 168
@bitcapulet case 4 -> "hurray" 3 -> "oops" var ->
[1, 2, 3] -> "123 list" end 169
@bitcapulet case 4 -> "hurray" 3 -> "oops" var ->
[1, 2, 3] -> "123 list" end 170
@bitcapulet case do_math(2) 4 -> "hurray" 3 -> "oops" var
-> "got number: #{var}" [1, 2, 3] -> "123 list" end 171
@bitcapulet case do_math(2) 4 -> "hurray" 3 -> "oops" var
-> "got number: #{var}" [1, 2, 3] -> "123 list" end 172
@bitcapulet case do_math(2) 4 -> "hurray" 3 -> "oops" [1,
2, 3] -> "123 list" var -> "got number: #{var}" end 173
@bitcapulet case do_math(2) 4 -> "hurray" 3 -> "oops" [1,
2, 3] -> "123 list" var -> "got number: #{var}" end 174
@bitcapulet %{} That long section. 175
@bitcapulet %{} That long section. Me need break. 176
@bitcapulet177
@bitcapulet178
@bitcapulet179
@bitcapulet180
@bitcapulet181
@bitcapulet Beam Processes Steal from telephony. 182
@bitcapulet183
@bitcapulet184
@bitcapulet185
@bitcapulet186
@bitcapulet187
@bitcapulet188
@bitcapulet189
@bitcapulet190
@bitcapulet191
@bitcapulet192
@bitcapulet193
@bitcapulet 134 Million Processes 194
@bitcapulet 134 Million Processes 195
@bitcapulet 134 Million Processes 196
@bitcapulet 134 Million Processes 197
@bitcapulet 134 Million Processes 198
@bitcapulet 134 Million Processes 199
@bitcapulet 134 Million Processes 200
@bitcapulet 134 Million Processes 201
@bitcapulet 134 Million Processes 202
@bitcapulet 134 Million Processes 203
@bitcapulet defmodule MyModule def phil(state) do phil(state + 1) end
end 204
@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
@bitcapulet Interactive Elixir (1.6.1) - press Ctrl+C to exit (type
h() ENTER for help) iex(1)> 206
@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
@bitcapulet iex(2)> pid = spawn(MyModule, :phil, 0) #PID<0.97.0> iex(3)> 208
@bitcapulet iex(2)> pid = spawn(MyModule, :phil, 0) #PID<0.97.0> iex(3)> Process.alive?(pid)
true iex(4)> 209
@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
@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
@bitcapulet spawn receive send 212 Built right into the language!
@bitcapulet A process is a recursive function that holds state
and lives at an address with a mailbox. <0.194.0> 213
@bitcapulet >%{} We back in OO-land! 214
@bitcapulet >%{} We back in OO-land! How this not just
uglier-Java?! 215
@bitcapulet216
@bitcapulet x x 217
@bitcapulet x x x x x x x x x
x x x x x 218
@bitcapulet219
@bitcapulet220
@bitcapulet221
@bitcapulet222
@bitcapulet223
@bitcapulet224
@bitcapulet 225
@bitcapulet 226
@bitcapulet 227
@bitcapulet 228
@bitcapulet 229
@bitcapulet 230
@bitcapulet 231
@bitcapulet %{} Break time 232
@bitcapulet233
@bitcapulet234
@bitcapulet235
@bitcapulet236
@bitcapulet237
@bitcapulet Function Signatures State complexity clearly. 238
@bitcapulet def run(a,b,c,d) do [d,c,b,a] end 239
@bitcapulet def run(a,b,c,d) do [d,c,b,a] end 240 Uneven
@bitcapulet def run(list) do [a,b,c,d] = list [d,c,b,a] end 241
@bitcapulet def run(list) do [a,b,c,d] = list [d,c,b,a] end 242
What if > 4 items?
@bitcapulet run([1,2,3,4,5]) ** (MatchError) no match of right hand side
value: [1, 2, 3, 4, 5] 243
@bitcapulet def run(list) do [a,b,c,d] = list [d,c,b,a] end 244
object?
@bitcapulet {tuple} 245
@bitcapulet quartet = {1,2,3,4} trio = {"one", 2, %{}} 246
@bitcapulet def run(tuple) do {a,b,c,d} = tuple {d,c,b,a} end 247
@bitcapulet def run(tuple) do {a,b,c,d} = tuple {d,c,b,a} end 248
@bitcapulet def run({a,b,c,d}) do {d,c,b,a} end 249
@bitcapulet def run(tuple = {a,b,c,d}) do IO.inspect(tuple) {d,c,b,a} end 250
@bitcapulet def run(tuple = {a,b,c,d}) do IO.inspect(tuple) {d,c,b,a} end 251
Now reverse 5!
@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
@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
@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
@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
@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
@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
@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
@bitcapulet This is why Java has factories! 259
@bitcapulet GenServer Steal from telephony. 260
@bitcapulet A process is a recursive function that holds state
and lives at an address with a mailbox. <0.194.0> 261
@bitcapulet A GenServer is like a Starfleet officer 262
@bitcapulet defmodule Phil do IO.puts("Phil got: " <> value) end
263
@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
@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
@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
@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
@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
@bitcapulet {:ok, pid} = GenServer.start_link(Phil, "arg") def init(_args), do: 0
Spawn a GenServer 269
@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
@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
@bitcapulet Synchronous requests reply = GenServer.call(pid, :say_something) 272 PID passing
gets old
@bitcapulet GenServer.start_link(Phil, "arg", name: :phil) Fee pid Registry 273
@bitcapulet GenServer.start_link(Phil, "arg", name: :phil) GenServer.cast(:phil, "a present with your
name on it") Fee pid Registry 274
@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
@bitcapulet Supervisors 276
@bitcapulet Supervisors 277
@bitcapulet defmodule CaptJoan do use Supervisor def init(_args) do children
= [ {Phil, []} ] Supervisor.init(children, strategy: :one_for_one) end end 278
@bitcapulet defmodule CaptJoan do use Supervisor def init(_args) do children
= [ {Phil, []} ] Supervisor.init(children, strategy: :one_for_one) end end 279
@bitcapulet defmodule CaptJoan do use Supervisor def init(_args) do children
= [ {Phil, []} ] Supervisor.init(children, strategy: :one_for_one) end end 280
@bitcapulet defmodule CaptJoan do use Supervisor def init(_args) do children
= [ {Phil, []}, {Phil, []}, {Phil, []} ] Supervisor.init(children, strategy: :one_for_one) end end 281
@bitcapulet defmodule CaptJoan do use Supervisor def init(_args) do children
= [ {Phil, []}, {Phil, []}, {Phil, []} ] Supervisor.init(children, strategy: :one_for_one) end end 282
@bitcapulet 283
@bitcapulet 284
@bitcapulet 285
@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
@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
@bitcapulet defmodule AdmiralRavi do use Supervisor def init(_args) do children
= [ {CaptJoan, []}, {CaptJoan, []}, {CaptJoan, []} ] Supervisor.init(children, strategy: :one_for_one) end end 288
@bitcapulet289
@bitcapulet290
@bitcapulet291
@bitcapulet292
@bitcapulet293
@bitcapulet294
@bitcapulet295
@bitcapulet296
@bitcapulet297
@bitcapulet298
@bitcapulet299
@bitcapulet300
@bitcapulet301
@bitcapulet302
@bitcapulet303
@bitcapulet #PID<0.96.0> <0.194.0> 304
@bitcapulet305 send(pid, "hello") GenServer.cast(:phil, "a present with your name on
it")
@bitcapulet ◍ timeouts ◍ linking processes ◌ monitoring ◌ trapping
exits ◍ error handling Other benefits 306
@bitcapulet defmodule AdmiralRavi do use Supervisor def init(_args) do children
= [ {CaptJoan, []}, {CaptJoan, []}, {CaptJoan, []} ] Supervisor.init(children, strategy: :one_for_one) end end 307
@bitcapulet %{} ME WANT MORE BREAK! 308
@bitcapulet
@bitcapulet
@bitcapulet
@bitcapulet
@bitcapulet
@bitcapulet Function Pipeline State complexity clearly 314
@bitcapulet def fav_capt(:kirk) do {:error, "Are you kidding me?"} end
def fav_capt(:picard) do {:ok, "You chose wisely."} end 315
@bitcapulet capt = :picard {:ok, message} = fav_capt(capt) IO.puts(message) 316
@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
@bitcapulet capt = :kirk case fav_capt(capt) {:ok, msg} -> msg
{:error, msg} -> Log.error("oops") end 318
@bitcapulet capt = :kirk case fav_capt(capt) {:ok, msg} -> msg
{:error, _msg} -> Log.error("oops") end 319
@bitcapulet capt = :kirk case fav_capt(capt) {:ok, msg} -> msg
{:error, _msg} -> Log.error("oops") {_, _msg} -> Log.error("What?!") end 320
@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
@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
@bitcapulet def respond({:ok, msg}) do Log.info("That went well.") msg end
def respond({:error, _msg}) do Log.error("oops") end 323
@bitcapulet respond(fav_capt(capt)) 324
@bitcapulet respond(fav_capt(capt)) capt |> fav_capt() |> respond() 325
@bitcapulet326
@bitcapulet capt |> fav_capt() |> respond() 327
@bitcapulet capt.fav_capt().respond() // This is constrained. 328
@bitcapulet capt |> fav_capt() |> respond() 329
@bitcapulet capt |> 330
@bitcapulet capt |> beam_to_planet() 331
@bitcapulet capt |> beam_to_planet() |> meet_aliens() 332
@bitcapulet capt |> beam_to_planet() |> meet_aliens() |> romance?() 333
@bitcapulet capt |> beam_to_planet() |> meet_aliens() |> romance?() |> case
do {:ok, details} -> log(details) :error -> kill_off_extra() end 334
@bitcapulet capt |> beam_to_planet() |> meet_aliens() |> romance?() |> case
do {:ok, details} -> log(details) :error -> kill_off_extra() end 335
@bitcapulet capt |> beam_to_planet() |> meet_aliens() |> romance?() |> case
do {:ok, details} -> log(details) :error -> kill_off_extra() end 336
@bitcapulet [1, 2, 3] 337
@bitcapulet [1, 2, 3] |> Enum.map(fn i -> i +
1 end) # [2, 3, 4] 338
@bitcapulet [1, 2, 3] |> Enum.map(fn i -> i +
1 end) |> Enum.sum() # 9 339
@bitcapulet %{} It late. Wrap it up. 340
@bitcapulet341 GenServer.start_link(CircleKeeper,[], name: :circle_keeper) GenServer.cast(:circle_keeper, {:add, %Circle{radius: 3}) total_area =
GenServer.call(:circle_keeper, :total_area)
@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
@bitcapulet {} 343
@bitcapulet %{} 344
@bitcapulet %{} 345
@bitcapulet %{} 346
@bitcapulet %{} Me here to say something inspiring to end
talk. 347
@bitcapulet %{} Language not really most important thing. 348
@bitcapulet %{} It matter you do job. 349
@bitcapulet %{} It matter you do job. And you happy
with job you do. 350
@bitcapulet %{} It also matter you make lots of money.
351
@bitcapulet %{} This language not make more money. 352
@bitcapulet %{} This language not make more money. But maybe
make more happy. 353
@bitcapulet %{} Adrian happy. 354
@bitcapulet %{} Adrian happy. He crazy. 355
@bitcapulet %{} Adrian happy. He crazy. But he happy. 356
@bitcapulet %{} He right about Elixir. It great. 357
@bitcapulet %{} Me hope you friends try it out. 358
@bitcapulet %{} 359
@bitcapulet %{} You know how you thank me. 360
@bitcapulet %{ } 361
@bitcapulet %{0} 362
@bitcapulet %{} 363
@bitcapulet %{*} 364
@bitcapulet %{} 365
@bitcapulet %{.} 366
@bitcapulet %{} 367
@bitcapulet %{} Bye! 368
@bitcapulet %{} 369
@bitcapulet %{} 370
@bitcapulet %{} 371
@bitcapulet %{} 372
@bitcapulet %{} 373
@bitcapulet %{} 374
@bitcapulet375
@bitcapulet Pinball Elixir Presentation template by SlidesCarnival 376 Adrian P.
Dunston @bitcapulet
[email protected]
joinpapa.com