SlideShare une entreprise Scribd logo
1  sur  51
Télécharger pour lire hors ligne
ELIXIR
Tolerância a Falhas para Adultos
Fabio Akita
Sintaxe
defmodule Teste do
def say(name) do
IO.puts("Hello #{name}")
end
end
Teste.say("Fabio")
# => "Hello Fabio"
defmodule Teste do
@spec say(String.t)
def say(name) when is_string(name) do
IO.puts "Hello " <> name
end
end
TiposeParêntesesOpcionais
defmodule Teste do
def factorial(n) do
if n == 0 do
1
else
n * factorial(n - 1)
end
end
end
Teste.factorial(10)
# => 3628800
defmodule Teste do
def factorial(1), do: 1
def factorial(n) do
n * factorial(n - 1)
end
end
Teste.factorial(10)
# => 3628800
CallbyPattern
%{last_name: name} = registro
# => ** (MatchError) no match of right hand side value:
%{foo: {:ok, [1, 2, 3, 4]}, name: "Fabio", year: 2017}
registro = %{name: "Fabio", year: 2017, foo: {:ok, [1,2,3,4]}}
%{name: name, foo: {:ok, result}} = registro
IO.puts Enum.join([name|result], ", ")
# => Fabio, 1, 2, 3, 4
registro = {:ok, %{name: "Fabio", last_name: "Akita"}}
{:ok, %{name: name}} = registro
IO.puts name
# => Fabio
{:ok, result} = Enum.fetch([1,2,3,4,5], 3)
IO.puts result
# => 4
registro = {:ok, %{name: "Fabio", last_name: "Akita"}}
{:ok, %{name: name}} = registro
IO.puts name
# => Fabio
registro = %{name: "Fabio", year: 2017, foo: {:ok, [1,2,3,4]}}
%{name: name, foo: {:ok, result}} = registro
IO.puts Enum.join([name|result], ", ")
# => Fabio, 1, 2, 3, 4
%{last_name: name} = registro
# => ** (MatchError) no match of right hand side value:
%{foo: {:ok, [1, 2, 3, 4]}, name: "Fabio", year: 2017}
PatternMatching
range = (1..100)
# => 1..100
interval = Enum.slice(range, 30, 10)
# => [31, 32, 33, 34, 35, 36, 37, 38, 39, 40]
evens = Enum.filter(interval, &(rem(&1,2) == 0))
# => [32, 34, 36, 38, 40]
multiplied = Enum.map(evens, &(&1 * 10))
# => [320, 340, 360, 380, 400]
Enum.take(multiplied, 2)
# => [320, 340]
range = (1..100)
interval = Enum.slice(range, 30, 10)
evens = Enum.filter(interval, fn(n) -> rem(n, 2) ==0 end)
multiplied = Enum.map(evens, fn(n) -> n * 10 end)
Enum.take(multiplied, 2)
range = (1..100)
# => 1..100
interval = Enum.slice(range, 30, 10)
# => [31, 32, 33, 34, 35, 36, 37, 38, 39, 40]
evens = Enum.filter(interval, &(rem(&1,2) == 0))
# => [32, 34, 36, 38, 40]
multiplied = Enum.map(evens, &(&1 * 10))
# => [320, 340, 360, 380, 400]
Enum.take(multiplied, 2)
# => [320, 340]
range = (1..100)
interval = Enum.slice(range, 30, 10)
evens = Enum.filter(interval, fn(n) -> rem(n, 2) ==0 end)
multiplied = Enum.map(evens, fn(n) -> n * 10 end)
Enum.take(multiplied, 2)
Enum.take(
Enum.map(
Enum.filter(
Enum.slice((1..100), 30, 10), &(rem(&1,2) == 0)
), &(&1 * 10)
), 2
)
range = (1..100)
interval = Enum.slice(range, 30, 10)
evens = Enum.filter(interval, fn(n) -> rem(n, 2) ==0 end)
multiplied = Enum.map(evens, fn(n) -> n * 10 end)
Enum.take(multiplied, 2)
(1..100)
|> Enum.slice(30, 10)
|> Enum.filter(&(rem(&1, 2)))
|> Enum.map(&(&1 * 10))
|> Enum.take(2)
PipeOperator|>
Fundações
iex(22)> function = fn -> IO.puts("Hello from function") end
#Function<20.99386804/0 in :erl_eval.expr/5>
iex(23)> function.()
Hello from function
:ok
iex(24)> pid = spawn(function)
Hello from function
#PID<0.112.0>
iex(25)> Process.alive?(pid)
false
iex(26)> Process.alive?(self)
true
iex(27)> self
#PID<0.85.0>
iex(22)> function = fn -> IO.puts("Hello from function") end
#Function<20.99386804/0 in :erl_eval.expr/5>
iex(23)> function.()
Hello from function
:ok
iex(24)> pid = spawn(function)
Hello from function
#PID<0.112.0>
iex(25)> Process.alive?(pid)
false
iex(26)> Process.alive?(self)
true
iex(27)> self
#PID<0.85.0>
iex(1)> pid = spawn(fn ->
...(1)> receive do
...(1)> {:say, from} -> send(from, "say what?")
...(1)> _ -> Process.exit(self, :normal)
...(1)> end
...(1)> end)
#PID<0.92.0>
iex(2)> Process.alive?(pid)
true
iex(3)> send(pid, {:say, self})
{:say, #PID<0.85.0>}
iex(4)> flush
"say what?"
:ok
iex(5)> send(pid, "blabla")
"blabla"
iex(6)> Process.alive?(pid)
false
iex(1)> pid = spawn(fn ->
...(1)> receive do
...(1)> {:say, from} -> send(from, "say what?")
...(1)> _ -> Process.exit(self, :normal)
...(1)> end
...(1)> end)
#PID<0.92.0>
iex(2)> Process.alive?(pid)
true
iex(3)> send(pid, {:say, self})
{:say, #PID<0.85.0>}
iex(4)> flush
"say what?"
:ok
iex(5)> send(pid, "blabla")
"blabla"
iex(6)> Process.alive?(pid)
false
Processos
• Hiper-leves (pode subir milhares)
• Totalmente isoladas (Process.send(pid, :kill))
• Comunicação por passagem de mensagens
• Um mailbox por processo (receive)
• Garbage Collector separado por Processo!
iex(1)> pid = spawn(fn ->
...(1)> receive do
...(1)> {:say, from} -> send(from, "say what?")
...(1)> _ -> Process.exit(self, :normal)
...(1)> end
...(1)> end)
iex(2)> Process.flag(:trap_exit, true)
false
iex(3)> send(pid, "blabla")
"blabla"
iex(4)> flush
{:EXIT, #PID<0.92.0>, :normal}
:ok
iex(1)> pid = spawn_link(fn ->
...(1)> receive do
...(1)> {:say, from} -> send(from, "say what?")
...(1)> _ -> Process.exit(self, :normal)
...(1)> end
...(1)> end)
#PID<0.92.0>
iex(2)> Process.flag(:trap_exit, true)
false
iex(3)> send(pid, "blabla")
"blabla"
iex(4)> flush
{:EXIT, #PID<0.92.0>, :normal}
:ok
ASYNCHRONOUSEXCEPTIONS
defmodule Stack do
def start_link do
Agent.start_link(fn -> [] end, name: __MODULE__)
end
def push(new_value) do
Agent.update(__MODULE__,
fn(state) ->
[new_value|state]
end)
end
def pop do
Agent.get_and_update(__MODULE__,
fn(state) ->
[head|tail] = state
{head, tail}
end)
end
end
iex(8)> Stack.start_link
{:ok, #PID<0.123.0>}
iex(9)> Stack.push "hello"
:ok
iex(10)> Stack.push "world"
:ok
iex(11)> Stack.pop
"world"
iex(12)> Stack.pop
"hello"
iex(13)> Process.list |> Enum.reverse |> Enum.at(0) |>
Process.exit(:kill)
** (EXIT from #PID<0.85.0>) evaluator process exited with reason:
killed
Interactive Elixir (1.5.2) - press Ctrl+C to exit (type h() ENTER
for help)
iex(1)> Stack.push "foo"
** (exit) exited in: GenServer.call(Stack, {:update,
#Function<1.117587580/1 in Stack.push/1>}, 5000)
** (EXIT) no process: the process is not alive or there's no
process currently associated with the given name, possibly because
its application isn't started
(elixir) lib/gen_server.ex:766: GenServer.call/3
iex(8)> Stack.start_link
{:ok, #PID<0.123.0>}
iex(9)> Stack.push "hello"
:ok
iex(10)> Stack.push "world"
:ok
iex(11)> Stack.pop
"world"
iex(12)> Stack.pop
"hello"
iex(13)> Process.list |> Enum.reverse |> Enum.at(0) |>
Process.exit(:kill)
** (EXIT from #PID<0.85.0>) evaluator process exited with reason:
killed
Interactive Elixir (1.5.2) - press Ctrl+C to exit (type h() ENTER
for help)
iex(1)> Stack.push "foo"
** (exit) exited in: GenServer.call(Stack, {:update,
#Function<1.117587580/1 in Stack.push/1>}, 5000)
** (EXIT) no process: the process is not alive or there's no
process currently associated with the given name, possibly because
its application isn't started
(elixir) lib/gen_server.ex:766: GenServer.call/3
defmodule Stack.Supervisor do
use Supervisor
def start_link do
Supervisor.start_link(__MODULE__, :ok)
end
def init(:ok) do
children = [ worker(Stack, []) ]
supervise(children, strategy: :one_for_one)
end
end
iex(3)> Stack.Supervisor.start_link
{:ok, #PID<0.127.0>}
iex(4)> Stack.push "hello"
:ok
iex(5)> Stack.push "world"
:ok
iex(6)> Stack.pop
"world"
iex(7)> Process.list |> Enum.reverse |> hd |> Process.exit(:kill)
true
iex(8)> Stack.push "foo"
:ok
iex(9)> Stack.push "bar"
:ok
iex(10)> Stack.pop
"bar"
iex(11)> Stack.pop
"foo"
iex(3)> Stack.Supervisor.start_link
{:ok, #PID<0.127.0>}
iex(4)> Stack.push "hello"
:ok
iex(5)> Stack.push "world"
:ok
iex(6)> Stack.pop
"world"
iex(7)> Process.list |> Enum.reverse |> hd |> Process.exit(:kill)
true
iex(8)> Stack.push "foo"
:ok
iex(9)> Stack.push "bar"
:ok
iex(10)> Stack.pop
"bar"
iex(11)> Stack.pop
"foo"
iex(8)> :observer.start
:ok
Distribuindo
Processamento
def flow_test do
1..@large_number
|> Flow.from_enumerable()
|> Flow.map(&(&1 * 3))
|> Flow.partition()
|> Flow.filter(
&Integer.is_odd/1)
|> Flow.partition()
|> Enum.sort
|> Enum.sum
end
end
defmodule Teste do
require Integer
@large_number 10_000_000
@slice 5_000
@concurrency 10
def enum_test do
1..@large_number
|> Enum.map(&(&1 * 3))
|> Enum.filter(
&Integer.is_odd/1)
|> Enum.sum
end
def stream_test do
1..@large_number
|> Stream.map(&(&1 * 3))
|> Stream.filter(
&Integer.is_odd/1)
|> Enum.sum
end
defmodule Teste do
require Integer
@large_number 10_000_000
@slice 5_000
@concurrency 10
def enum_test do
1..@large_number
|> Enum.map(&(&1 * 3))
|> Enum.filter(
&Integer.is_odd/1)
|> Enum.sum
end
def stream_test do
1..@large_number
|> Stream.map(&(&1 * 3))
|> Stream.filter(
&Integer.is_odd/1)
|> Enum.sum
end
def flow_test do
1..@large_number
|> Flow.from_enumerable()
|> Flow.map(&(&1 * 3))
|> Flow.partition()
|> Flow.filter(
&Integer.is_odd/1)
|> Flow.partition()
|> Enum.sort
|> Enum.sum
end
end
Sistema Operacional
para Aplicações
Distribuídas
Versão Lançamento
1.0 18/09/2014
1.1 28/09/2015
1.2 03/01/2016
1.3 21/06/2016
1.4 05/01/2017
1.5 25/07/2017
OBRIGADO
slideshare.net/akitaonrails
@akitaonrails

Contenu connexe

Tendances

The Ring programming language version 1.5.4 book - Part 27 of 185
The Ring programming language version 1.5.4 book - Part 27 of 185The Ring programming language version 1.5.4 book - Part 27 of 185
The Ring programming language version 1.5.4 book - Part 27 of 185Mahmoud Samir Fayed
 
Gabriele Lana - The Magic of Elixir
Gabriele Lana - The Magic of ElixirGabriele Lana - The Magic of Elixir
Gabriele Lana - The Magic of ElixirCodemotion
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語ikdysfm
 
SWP - A Generic Language Parser
SWP - A Generic Language ParserSWP - A Generic Language Parser
SWP - A Generic Language Parserkamaelian
 
The Ring programming language version 1.6 book - Part 48 of 189
The Ring programming language version 1.6 book - Part 48 of 189The Ring programming language version 1.6 book - Part 48 of 189
The Ring programming language version 1.6 book - Part 48 of 189Mahmoud Samir Fayed
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a ElixirSvet Ivantchev
 
Intro to OTP in Elixir
Intro to OTP in ElixirIntro to OTP in Elixir
Intro to OTP in ElixirJesse Anderson
 
Html5 game, websocket e arduino
Html5 game, websocket e arduino Html5 game, websocket e arduino
Html5 game, websocket e arduino Giuseppe Modarelli
 
The Ring programming language version 1.6 book - Part 185 of 189
The Ring programming language version 1.6 book - Part 185 of 189The Ring programming language version 1.6 book - Part 185 of 189
The Ring programming language version 1.6 book - Part 185 of 189Mahmoud Samir Fayed
 
Html5 game, websocket e arduino
Html5 game, websocket e arduinoHtml5 game, websocket e arduino
Html5 game, websocket e arduinomonksoftwareit
 
The Ring programming language version 1.10 book - Part 71 of 212
The Ring programming language version 1.10 book - Part 71 of 212The Ring programming language version 1.10 book - Part 71 of 212
The Ring programming language version 1.10 book - Part 71 of 212Mahmoud Samir Fayed
 
Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3guesta3202
 
Swift에서 꼬리재귀 사용기 (Tail Recursion)
Swift에서 꼬리재귀 사용기 (Tail Recursion)Swift에서 꼬리재귀 사용기 (Tail Recursion)
Swift에서 꼬리재귀 사용기 (Tail Recursion)진성 오
 
The Ring programming language version 1.5.4 book - Part 46 of 185
The Ring programming language version 1.5.4 book - Part 46 of 185The Ring programming language version 1.5.4 book - Part 46 of 185
The Ring programming language version 1.5.4 book - Part 46 of 185Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 57 of 202
The Ring programming language version 1.8 book - Part 57 of 202The Ring programming language version 1.8 book - Part 57 of 202
The Ring programming language version 1.8 book - Part 57 of 202Mahmoud Samir Fayed
 

Tendances (20)

The Ring programming language version 1.5.4 book - Part 27 of 185
The Ring programming language version 1.5.4 book - Part 27 of 185The Ring programming language version 1.5.4 book - Part 27 of 185
The Ring programming language version 1.5.4 book - Part 27 of 185
 
Gabriele Lana - The Magic of Elixir
Gabriele Lana - The Magic of ElixirGabriele Lana - The Magic of Elixir
Gabriele Lana - The Magic of Elixir
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
 
SWP - A Generic Language Parser
SWP - A Generic Language ParserSWP - A Generic Language Parser
SWP - A Generic Language Parser
 
The Ring programming language version 1.6 book - Part 48 of 189
The Ring programming language version 1.6 book - Part 48 of 189The Ring programming language version 1.6 book - Part 48 of 189
The Ring programming language version 1.6 book - Part 48 of 189
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a Elixir
 
Intro to OTP in Elixir
Intro to OTP in ElixirIntro to OTP in Elixir
Intro to OTP in Elixir
 
Html5 game, websocket e arduino
Html5 game, websocket e arduino Html5 game, websocket e arduino
Html5 game, websocket e arduino
 
Introducing to Asynchronous Programming
Introducing to Asynchronous  ProgrammingIntroducing to Asynchronous  Programming
Introducing to Asynchronous Programming
 
The Ring programming language version 1.6 book - Part 185 of 189
The Ring programming language version 1.6 book - Part 185 of 189The Ring programming language version 1.6 book - Part 185 of 189
The Ring programming language version 1.6 book - Part 185 of 189
 
Html5 game, websocket e arduino
Html5 game, websocket e arduinoHtml5 game, websocket e arduino
Html5 game, websocket e arduino
 
The Ring programming language version 1.10 book - Part 71 of 212
The Ring programming language version 1.10 book - Part 71 of 212The Ring programming language version 1.10 book - Part 71 of 212
The Ring programming language version 1.10 book - Part 71 of 212
 
Corona sdk
Corona sdkCorona sdk
Corona sdk
 
C++ L04-Array+String
C++ L04-Array+StringC++ L04-Array+String
C++ L04-Array+String
 
Ruby things
Ruby thingsRuby things
Ruby things
 
Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3
 
Lập trình Python cơ bản
Lập trình Python cơ bảnLập trình Python cơ bản
Lập trình Python cơ bản
 
Swift에서 꼬리재귀 사용기 (Tail Recursion)
Swift에서 꼬리재귀 사용기 (Tail Recursion)Swift에서 꼬리재귀 사용기 (Tail Recursion)
Swift에서 꼬리재귀 사용기 (Tail Recursion)
 
The Ring programming language version 1.5.4 book - Part 46 of 185
The Ring programming language version 1.5.4 book - Part 46 of 185The Ring programming language version 1.5.4 book - Part 46 of 185
The Ring programming language version 1.5.4 book - Part 46 of 185
 
The Ring programming language version 1.8 book - Part 57 of 202
The Ring programming language version 1.8 book - Part 57 of 202The Ring programming language version 1.8 book - Part 57 of 202
The Ring programming language version 1.8 book - Part 57 of 202
 

Similaire à Elixir -Tolerância a Falhas para Adultos - GDG Campinas

Elixir - Tolerância a Falhas para Adultos - Secot VIII Sorocaba
Elixir - Tolerância a Falhas para Adultos - Secot VIII SorocabaElixir - Tolerância a Falhas para Adultos - Secot VIII Sorocaba
Elixir - Tolerância a Falhas para Adultos - Secot VIII SorocabaFabio Akita
 
GenServer in Action – Yurii Bodarev
GenServer in Action – Yurii Bodarev   GenServer in Action – Yurii Bodarev
GenServer in Action – Yurii Bodarev Elixir Club
 
GE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingGE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingMuthu Vinayagam
 
funwithalgorithms.pptx
funwithalgorithms.pptxfunwithalgorithms.pptx
funwithalgorithms.pptxTess Ferrandez
 
関数プログラミングことはじめ revival
関数プログラミングことはじめ revival関数プログラミングことはじめ revival
関数プログラミングことはじめ revivalNaoki Kitora
 
Build a compiler in 2hrs - NCrafts Paris 2015
Build a compiler in 2hrs -  NCrafts Paris 2015Build a compiler in 2hrs -  NCrafts Paris 2015
Build a compiler in 2hrs - NCrafts Paris 2015Phillip Trelford
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?Adam Dudczak
 
Monadologie
MonadologieMonadologie
Monadologieleague
 
関数潮流(Function Tendency)
関数潮流(Function Tendency)関数潮流(Function Tendency)
関数潮流(Function Tendency)riue
 
The Ring programming language version 1.5.2 book - Part 24 of 181
The Ring programming language version 1.5.2 book - Part 24 of 181The Ring programming language version 1.5.2 book - Part 24 of 181
The Ring programming language version 1.5.2 book - Part 24 of 181Mahmoud Samir Fayed
 
FS2 for Fun and Profit
FS2 for Fun and ProfitFS2 for Fun and Profit
FS2 for Fun and ProfitAdil Akhter
 
Go: It's Not Just For Google
Go: It's Not Just For GoogleGo: It's Not Just For Google
Go: It's Not Just For GoogleEleanor McHugh
 
The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 25 of 185
The Ring programming language version 1.5.4 book - Part 25 of 185The Ring programming language version 1.5.4 book - Part 25 of 185
The Ring programming language version 1.5.4 book - Part 25 of 185Mahmoud Samir Fayed
 
Scala kansai summit-2016
Scala kansai summit-2016Scala kansai summit-2016
Scala kansai summit-2016Naoki Kitora
 

Similaire à Elixir -Tolerância a Falhas para Adultos - GDG Campinas (20)

Elixir - Tolerância a Falhas para Adultos - Secot VIII Sorocaba
Elixir - Tolerância a Falhas para Adultos - Secot VIII SorocabaElixir - Tolerância a Falhas para Adultos - Secot VIII Sorocaba
Elixir - Tolerância a Falhas para Adultos - Secot VIII Sorocaba
 
GenServer in action
GenServer in actionGenServer in action
GenServer in action
 
GenServer in Action – Yurii Bodarev
GenServer in Action – Yurii Bodarev   GenServer in Action – Yurii Bodarev
GenServer in Action – Yurii Bodarev
 
GE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingGE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python Programming
 
funwithalgorithms.pptx
funwithalgorithms.pptxfunwithalgorithms.pptx
funwithalgorithms.pptx
 
関数プログラミングことはじめ revival
関数プログラミングことはじめ revival関数プログラミングことはじめ revival
関数プログラミングことはじめ revival
 
Build a compiler in 2hrs - NCrafts Paris 2015
Build a compiler in 2hrs -  NCrafts Paris 2015Build a compiler in 2hrs -  NCrafts Paris 2015
Build a compiler in 2hrs - NCrafts Paris 2015
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?
 
Monadologie
MonadologieMonadologie
Monadologie
 
Java VS Python
Java VS PythonJava VS Python
Java VS Python
 
関数潮流(Function Tendency)
関数潮流(Function Tendency)関数潮流(Function Tendency)
関数潮流(Function Tendency)
 
The Ring programming language version 1.5.2 book - Part 24 of 181
The Ring programming language version 1.5.2 book - Part 24 of 181The Ring programming language version 1.5.2 book - Part 24 of 181
The Ring programming language version 1.5.2 book - Part 24 of 181
 
FS2 for Fun and Profit
FS2 for Fun and ProfitFS2 for Fun and Profit
FS2 for Fun and Profit
 
Go: It's Not Just For Google
Go: It's Not Just For GoogleGo: It's Not Just For Google
Go: It's Not Just For Google
 
The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181
 
The Ring programming language version 1.5.4 book - Part 25 of 185
The Ring programming language version 1.5.4 book - Part 25 of 185The Ring programming language version 1.5.4 book - Part 25 of 185
The Ring programming language version 1.5.4 book - Part 25 of 185
 
Basics
BasicsBasics
Basics
 
Scala kansai summit-2016
Scala kansai summit-2016Scala kansai summit-2016
Scala kansai summit-2016
 
Python 1 liners
Python 1 linersPython 1 liners
Python 1 liners
 
Elixir cheatsheet
Elixir cheatsheetElixir cheatsheet
Elixir cheatsheet
 

Plus de Fabio Akita

Devconf 2019 - São Carlos
Devconf 2019 - São CarlosDevconf 2019 - São Carlos
Devconf 2019 - São CarlosFabio Akita
 
Meetup Nerdzão - English Talk about Languages
Meetup Nerdzão  - English Talk about LanguagesMeetup Nerdzão  - English Talk about Languages
Meetup Nerdzão - English Talk about LanguagesFabio Akita
 
Desmistificando Blockchains p/ Developers - Criciuma Dev Conf 2018
Desmistificando Blockchains p/ Developers - Criciuma Dev Conf 2018Desmistificando Blockchains p/ Developers - Criciuma Dev Conf 2018
Desmistificando Blockchains p/ Developers - Criciuma Dev Conf 2018Fabio Akita
 
Desmistificando Blockchains - 20o Encontro Locaweb SP
Desmistificando Blockchains - 20o Encontro Locaweb SPDesmistificando Blockchains - 20o Encontro Locaweb SP
Desmistificando Blockchains - 20o Encontro Locaweb SPFabio Akita
 
Desmistificando Blockchains - Insiter Goiania
Desmistificando Blockchains - Insiter GoianiaDesmistificando Blockchains - Insiter Goiania
Desmistificando Blockchains - Insiter GoianiaFabio Akita
 
Blockchain em 7 minutos - 7Masters
Blockchain em 7 minutos - 7MastersBlockchain em 7 minutos - 7Masters
Blockchain em 7 minutos - 7MastersFabio Akita
 
Desmistificando Mitos de Tech Startups - Intercon 2017
Desmistificando Mitos de Tech Startups - Intercon 2017Desmistificando Mitos de Tech Startups - Intercon 2017
Desmistificando Mitos de Tech Startups - Intercon 2017Fabio Akita
 
30 Days to Elixir and Crystal and Back to Ruby
30 Days to Elixir and Crystal and Back to Ruby30 Days to Elixir and Crystal and Back to Ruby
30 Days to Elixir and Crystal and Back to RubyFabio Akita
 
Uma Discussão sobre a Carreira de TI
Uma Discussão sobre a Carreira de TIUma Discussão sobre a Carreira de TI
Uma Discussão sobre a Carreira de TIFabio Akita
 
THE CONF - Opening Keynote
THE CONF - Opening KeynoteTHE CONF - Opening Keynote
THE CONF - Opening KeynoteFabio Akita
 
A Journey through New Languages - Rancho Dev 2017
A Journey through New Languages - Rancho Dev 2017A Journey through New Languages - Rancho Dev 2017
A Journey through New Languages - Rancho Dev 2017Fabio Akita
 
Desmistificando Mitos de Startups - Sebrae - AP
Desmistificando Mitos de Startups - Sebrae - APDesmistificando Mitos de Startups - Sebrae - AP
Desmistificando Mitos de Startups - Sebrae - APFabio Akita
 
A Journey through New Languages - Guru Sorocaba 2017
A Journey through New Languages - Guru Sorocaba 2017A Journey through New Languages - Guru Sorocaba 2017
A Journey through New Languages - Guru Sorocaba 2017Fabio Akita
 
A Journey through New Languages - Insiter 2017
A Journey through New Languages - Insiter 2017A Journey through New Languages - Insiter 2017
A Journey through New Languages - Insiter 2017Fabio Akita
 
A Journey through New Languages - Locaweb Tech Day
A Journey through New Languages - Locaweb Tech DayA Journey through New Languages - Locaweb Tech Day
A Journey through New Languages - Locaweb Tech DayFabio Akita
 
A Journey through new Languages - Intercon 2016
A Journey through new Languages - Intercon 2016A Journey through new Languages - Intercon 2016
A Journey through new Languages - Intercon 2016Fabio Akita
 
Premature Optimization 2.0 - Intercon 2016
Premature Optimization 2.0 - Intercon 2016Premature Optimization 2.0 - Intercon 2016
Premature Optimization 2.0 - Intercon 2016Fabio Akita
 
Conexão Kinghost - Otimização Prematura
Conexão Kinghost - Otimização PrematuraConexão Kinghost - Otimização Prematura
Conexão Kinghost - Otimização PrematuraFabio Akita
 
The Open Commerce Conference - Premature Optimisation: The Root of All Evil
The Open Commerce Conference - Premature Optimisation: The Root of All EvilThe Open Commerce Conference - Premature Optimisation: The Root of All Evil
The Open Commerce Conference - Premature Optimisation: The Root of All EvilFabio Akita
 
Premature optimisation: The Root of All Evil
Premature optimisation: The Root of All EvilPremature optimisation: The Root of All Evil
Premature optimisation: The Root of All EvilFabio Akita
 

Plus de Fabio Akita (20)

Devconf 2019 - São Carlos
Devconf 2019 - São CarlosDevconf 2019 - São Carlos
Devconf 2019 - São Carlos
 
Meetup Nerdzão - English Talk about Languages
Meetup Nerdzão  - English Talk about LanguagesMeetup Nerdzão  - English Talk about Languages
Meetup Nerdzão - English Talk about Languages
 
Desmistificando Blockchains p/ Developers - Criciuma Dev Conf 2018
Desmistificando Blockchains p/ Developers - Criciuma Dev Conf 2018Desmistificando Blockchains p/ Developers - Criciuma Dev Conf 2018
Desmistificando Blockchains p/ Developers - Criciuma Dev Conf 2018
 
Desmistificando Blockchains - 20o Encontro Locaweb SP
Desmistificando Blockchains - 20o Encontro Locaweb SPDesmistificando Blockchains - 20o Encontro Locaweb SP
Desmistificando Blockchains - 20o Encontro Locaweb SP
 
Desmistificando Blockchains - Insiter Goiania
Desmistificando Blockchains - Insiter GoianiaDesmistificando Blockchains - Insiter Goiania
Desmistificando Blockchains - Insiter Goiania
 
Blockchain em 7 minutos - 7Masters
Blockchain em 7 minutos - 7MastersBlockchain em 7 minutos - 7Masters
Blockchain em 7 minutos - 7Masters
 
Desmistificando Mitos de Tech Startups - Intercon 2017
Desmistificando Mitos de Tech Startups - Intercon 2017Desmistificando Mitos de Tech Startups - Intercon 2017
Desmistificando Mitos de Tech Startups - Intercon 2017
 
30 Days to Elixir and Crystal and Back to Ruby
30 Days to Elixir and Crystal and Back to Ruby30 Days to Elixir and Crystal and Back to Ruby
30 Days to Elixir and Crystal and Back to Ruby
 
Uma Discussão sobre a Carreira de TI
Uma Discussão sobre a Carreira de TIUma Discussão sobre a Carreira de TI
Uma Discussão sobre a Carreira de TI
 
THE CONF - Opening Keynote
THE CONF - Opening KeynoteTHE CONF - Opening Keynote
THE CONF - Opening Keynote
 
A Journey through New Languages - Rancho Dev 2017
A Journey through New Languages - Rancho Dev 2017A Journey through New Languages - Rancho Dev 2017
A Journey through New Languages - Rancho Dev 2017
 
Desmistificando Mitos de Startups - Sebrae - AP
Desmistificando Mitos de Startups - Sebrae - APDesmistificando Mitos de Startups - Sebrae - AP
Desmistificando Mitos de Startups - Sebrae - AP
 
A Journey through New Languages - Guru Sorocaba 2017
A Journey through New Languages - Guru Sorocaba 2017A Journey through New Languages - Guru Sorocaba 2017
A Journey through New Languages - Guru Sorocaba 2017
 
A Journey through New Languages - Insiter 2017
A Journey through New Languages - Insiter 2017A Journey through New Languages - Insiter 2017
A Journey through New Languages - Insiter 2017
 
A Journey through New Languages - Locaweb Tech Day
A Journey through New Languages - Locaweb Tech DayA Journey through New Languages - Locaweb Tech Day
A Journey through New Languages - Locaweb Tech Day
 
A Journey through new Languages - Intercon 2016
A Journey through new Languages - Intercon 2016A Journey through new Languages - Intercon 2016
A Journey through new Languages - Intercon 2016
 
Premature Optimization 2.0 - Intercon 2016
Premature Optimization 2.0 - Intercon 2016Premature Optimization 2.0 - Intercon 2016
Premature Optimization 2.0 - Intercon 2016
 
Conexão Kinghost - Otimização Prematura
Conexão Kinghost - Otimização PrematuraConexão Kinghost - Otimização Prematura
Conexão Kinghost - Otimização Prematura
 
The Open Commerce Conference - Premature Optimisation: The Root of All Evil
The Open Commerce Conference - Premature Optimisation: The Root of All EvilThe Open Commerce Conference - Premature Optimisation: The Root of All Evil
The Open Commerce Conference - Premature Optimisation: The Root of All Evil
 
Premature optimisation: The Root of All Evil
Premature optimisation: The Root of All EvilPremature optimisation: The Root of All Evil
Premature optimisation: The Root of All Evil
 

Dernier

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 

Dernier (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

Elixir -Tolerância a Falhas para Adultos - GDG Campinas

  • 1. ELIXIR Tolerância a Falhas para Adultos Fabio Akita
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 15. defmodule Teste do def say(name) do IO.puts("Hello #{name}") end end Teste.say("Fabio") # => "Hello Fabio" defmodule Teste do @spec say(String.t) def say(name) when is_string(name) do IO.puts "Hello " <> name end end TiposeParêntesesOpcionais
  • 16. defmodule Teste do def factorial(n) do if n == 0 do 1 else n * factorial(n - 1) end end end Teste.factorial(10) # => 3628800 defmodule Teste do def factorial(1), do: 1 def factorial(n) do n * factorial(n - 1) end end Teste.factorial(10) # => 3628800 CallbyPattern
  • 17. %{last_name: name} = registro # => ** (MatchError) no match of right hand side value: %{foo: {:ok, [1, 2, 3, 4]}, name: "Fabio", year: 2017} registro = %{name: "Fabio", year: 2017, foo: {:ok, [1,2,3,4]}} %{name: name, foo: {:ok, result}} = registro IO.puts Enum.join([name|result], ", ") # => Fabio, 1, 2, 3, 4 registro = {:ok, %{name: "Fabio", last_name: "Akita"}} {:ok, %{name: name}} = registro IO.puts name # => Fabio {:ok, result} = Enum.fetch([1,2,3,4,5], 3) IO.puts result # => 4 registro = {:ok, %{name: "Fabio", last_name: "Akita"}} {:ok, %{name: name}} = registro IO.puts name # => Fabio registro = %{name: "Fabio", year: 2017, foo: {:ok, [1,2,3,4]}} %{name: name, foo: {:ok, result}} = registro IO.puts Enum.join([name|result], ", ") # => Fabio, 1, 2, 3, 4 %{last_name: name} = registro # => ** (MatchError) no match of right hand side value: %{foo: {:ok, [1, 2, 3, 4]}, name: "Fabio", year: 2017} PatternMatching
  • 18. range = (1..100) # => 1..100 interval = Enum.slice(range, 30, 10) # => [31, 32, 33, 34, 35, 36, 37, 38, 39, 40] evens = Enum.filter(interval, &(rem(&1,2) == 0)) # => [32, 34, 36, 38, 40] multiplied = Enum.map(evens, &(&1 * 10)) # => [320, 340, 360, 380, 400] Enum.take(multiplied, 2) # => [320, 340] range = (1..100) interval = Enum.slice(range, 30, 10) evens = Enum.filter(interval, fn(n) -> rem(n, 2) ==0 end) multiplied = Enum.map(evens, fn(n) -> n * 10 end) Enum.take(multiplied, 2) range = (1..100) # => 1..100 interval = Enum.slice(range, 30, 10) # => [31, 32, 33, 34, 35, 36, 37, 38, 39, 40] evens = Enum.filter(interval, &(rem(&1,2) == 0)) # => [32, 34, 36, 38, 40] multiplied = Enum.map(evens, &(&1 * 10)) # => [320, 340, 360, 380, 400] Enum.take(multiplied, 2) # => [320, 340]
  • 19. range = (1..100) interval = Enum.slice(range, 30, 10) evens = Enum.filter(interval, fn(n) -> rem(n, 2) ==0 end) multiplied = Enum.map(evens, fn(n) -> n * 10 end) Enum.take(multiplied, 2) Enum.take( Enum.map( Enum.filter( Enum.slice((1..100), 30, 10), &(rem(&1,2) == 0) ), &(&1 * 10) ), 2 )
  • 20. range = (1..100) interval = Enum.slice(range, 30, 10) evens = Enum.filter(interval, fn(n) -> rem(n, 2) ==0 end) multiplied = Enum.map(evens, fn(n) -> n * 10 end) Enum.take(multiplied, 2) (1..100) |> Enum.slice(30, 10) |> Enum.filter(&(rem(&1, 2))) |> Enum.map(&(&1 * 10)) |> Enum.take(2) PipeOperator|>
  • 22. iex(22)> function = fn -> IO.puts("Hello from function") end #Function<20.99386804/0 in :erl_eval.expr/5> iex(23)> function.() Hello from function :ok iex(24)> pid = spawn(function) Hello from function #PID<0.112.0> iex(25)> Process.alive?(pid) false iex(26)> Process.alive?(self) true iex(27)> self #PID<0.85.0> iex(22)> function = fn -> IO.puts("Hello from function") end #Function<20.99386804/0 in :erl_eval.expr/5> iex(23)> function.() Hello from function :ok iex(24)> pid = spawn(function) Hello from function #PID<0.112.0> iex(25)> Process.alive?(pid) false iex(26)> Process.alive?(self) true iex(27)> self #PID<0.85.0>
  • 23. iex(1)> pid = spawn(fn -> ...(1)> receive do ...(1)> {:say, from} -> send(from, "say what?") ...(1)> _ -> Process.exit(self, :normal) ...(1)> end ...(1)> end) #PID<0.92.0> iex(2)> Process.alive?(pid) true iex(3)> send(pid, {:say, self}) {:say, #PID<0.85.0>} iex(4)> flush "say what?" :ok iex(5)> send(pid, "blabla") "blabla" iex(6)> Process.alive?(pid) false iex(1)> pid = spawn(fn -> ...(1)> receive do ...(1)> {:say, from} -> send(from, "say what?") ...(1)> _ -> Process.exit(self, :normal) ...(1)> end ...(1)> end) #PID<0.92.0> iex(2)> Process.alive?(pid) true iex(3)> send(pid, {:say, self}) {:say, #PID<0.85.0>} iex(4)> flush "say what?" :ok iex(5)> send(pid, "blabla") "blabla" iex(6)> Process.alive?(pid) false
  • 24. Processos • Hiper-leves (pode subir milhares) • Totalmente isoladas (Process.send(pid, :kill)) • Comunicação por passagem de mensagens • Um mailbox por processo (receive) • Garbage Collector separado por Processo!
  • 25. iex(1)> pid = spawn(fn -> ...(1)> receive do ...(1)> {:say, from} -> send(from, "say what?") ...(1)> _ -> Process.exit(self, :normal) ...(1)> end ...(1)> end)
  • 26. iex(2)> Process.flag(:trap_exit, true) false iex(3)> send(pid, "blabla") "blabla" iex(4)> flush {:EXIT, #PID<0.92.0>, :normal} :ok iex(1)> pid = spawn_link(fn -> ...(1)> receive do ...(1)> {:say, from} -> send(from, "say what?") ...(1)> _ -> Process.exit(self, :normal) ...(1)> end ...(1)> end) #PID<0.92.0> iex(2)> Process.flag(:trap_exit, true) false iex(3)> send(pid, "blabla") "blabla" iex(4)> flush {:EXIT, #PID<0.92.0>, :normal} :ok ASYNCHRONOUSEXCEPTIONS
  • 27. defmodule Stack do def start_link do Agent.start_link(fn -> [] end, name: __MODULE__) end def push(new_value) do Agent.update(__MODULE__, fn(state) -> [new_value|state] end) end def pop do Agent.get_and_update(__MODULE__, fn(state) -> [head|tail] = state {head, tail} end) end end
  • 28. iex(8)> Stack.start_link {:ok, #PID<0.123.0>} iex(9)> Stack.push "hello" :ok iex(10)> Stack.push "world" :ok iex(11)> Stack.pop "world" iex(12)> Stack.pop "hello" iex(13)> Process.list |> Enum.reverse |> Enum.at(0) |> Process.exit(:kill) ** (EXIT from #PID<0.85.0>) evaluator process exited with reason: killed Interactive Elixir (1.5.2) - press Ctrl+C to exit (type h() ENTER for help) iex(1)> Stack.push "foo" ** (exit) exited in: GenServer.call(Stack, {:update, #Function<1.117587580/1 in Stack.push/1>}, 5000) ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started (elixir) lib/gen_server.ex:766: GenServer.call/3 iex(8)> Stack.start_link {:ok, #PID<0.123.0>} iex(9)> Stack.push "hello" :ok iex(10)> Stack.push "world" :ok iex(11)> Stack.pop "world" iex(12)> Stack.pop "hello" iex(13)> Process.list |> Enum.reverse |> Enum.at(0) |> Process.exit(:kill) ** (EXIT from #PID<0.85.0>) evaluator process exited with reason: killed Interactive Elixir (1.5.2) - press Ctrl+C to exit (type h() ENTER for help) iex(1)> Stack.push "foo" ** (exit) exited in: GenServer.call(Stack, {:update, #Function<1.117587580/1 in Stack.push/1>}, 5000) ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started (elixir) lib/gen_server.ex:766: GenServer.call/3
  • 29. defmodule Stack.Supervisor do use Supervisor def start_link do Supervisor.start_link(__MODULE__, :ok) end def init(:ok) do children = [ worker(Stack, []) ] supervise(children, strategy: :one_for_one) end end
  • 30. iex(3)> Stack.Supervisor.start_link {:ok, #PID<0.127.0>} iex(4)> Stack.push "hello" :ok iex(5)> Stack.push "world" :ok iex(6)> Stack.pop "world" iex(7)> Process.list |> Enum.reverse |> hd |> Process.exit(:kill) true iex(8)> Stack.push "foo" :ok iex(9)> Stack.push "bar" :ok iex(10)> Stack.pop "bar" iex(11)> Stack.pop "foo" iex(3)> Stack.Supervisor.start_link {:ok, #PID<0.127.0>} iex(4)> Stack.push "hello" :ok iex(5)> Stack.push "world" :ok iex(6)> Stack.pop "world" iex(7)> Process.list |> Enum.reverse |> hd |> Process.exit(:kill) true iex(8)> Stack.push "foo" :ok iex(9)> Stack.push "bar" :ok iex(10)> Stack.pop "bar" iex(11)> Stack.pop "foo"
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 44. def flow_test do 1..@large_number |> Flow.from_enumerable() |> Flow.map(&(&1 * 3)) |> Flow.partition() |> Flow.filter( &Integer.is_odd/1) |> Flow.partition() |> Enum.sort |> Enum.sum end end defmodule Teste do require Integer @large_number 10_000_000 @slice 5_000 @concurrency 10 def enum_test do 1..@large_number |> Enum.map(&(&1 * 3)) |> Enum.filter( &Integer.is_odd/1) |> Enum.sum end def stream_test do 1..@large_number |> Stream.map(&(&1 * 3)) |> Stream.filter( &Integer.is_odd/1) |> Enum.sum end defmodule Teste do require Integer @large_number 10_000_000 @slice 5_000 @concurrency 10 def enum_test do 1..@large_number |> Enum.map(&(&1 * 3)) |> Enum.filter( &Integer.is_odd/1) |> Enum.sum end def stream_test do 1..@large_number |> Stream.map(&(&1 * 3)) |> Stream.filter( &Integer.is_odd/1) |> Enum.sum end def flow_test do 1..@large_number |> Flow.from_enumerable() |> Flow.map(&(&1 * 3)) |> Flow.partition() |> Flow.filter( &Integer.is_odd/1) |> Flow.partition() |> Enum.sort |> Enum.sum end end
  • 45.
  • 47. Versão Lançamento 1.0 18/09/2014 1.1 28/09/2015 1.2 03/01/2016 1.3 21/06/2016 1.4 05/01/2017 1.5 25/07/2017
  • 48.
  • 49.
  • 50.