SlideShare a Scribd company logo
ELIXIRTolerância a Falhas para Adultos
Fabio Akita
@akitaonrails@akitaonrails
Rubyconf Brasil 2016 – 23 e 24 de SetembroRubyconf Brasil 2016 – 23 e 24 de Setembro
Rubyconf Brasil 2016 – 23 e 24 de SetembroRubyconf Brasil 2016 – 23 e 24 de Setembro
Rubyconf Brasil 2016 – 23 e 24 de SetembroRubyconf Brasil 2016 – 23 e 24 de Setembro
Chris McCordChris McCord José ValimJosé Valim
Joe Armstrong - EricssonJoe Armstrong - Ericsson
defmodule Teste do
def say(name) do
IO.puts("Hello #{name}")
end
end
Teste.say("Fabio")
defmodule Teste do
@spec say(String.t)
def say(name) when is_string(name) do
IO.puts "Hello " <> name
end
end
Teste.say "Fabio"
OPTIONAL PARENTHESIS
-module(teste).
-export([qsort/1]).
qsort([]) -> [];
qsort([Pivot|T]) ->
qsort([X||X<-T,X =< Pivot]) ++
[Pivot] ++
qsort([X||X<-T,X > Pivot]).
defmodule Teste do
def qsort([]), do: []
def qsort([pivot|t]) do
qsort(for x <- t, x < pivot, do: x) ++
[pivot] ++
qsort(for x <- t, x >= pivot, do: x)
end
end
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(0), do: 1
def factorial(n) do
n * factorial(n - 1)
end
end
Teste.factorial(10)
# => 3628800
CALL BY PATTERN
{:ok, result} = Enum.fetch([1, 2, 3, 4], 3)
IO.puts result
# => 4
registro = {:ok, %{name: "Fabio", last_name: "Akita"}}
{:ok, %{name: name}} = registro
IO.puts name
# => Fabio
registro = %{name: "Fabio", year: 2016, foo: {:ok, [1, 2, 3]}}
%{name: name, foo: {:ok, result}} = registro
IO.puts Enum.join([name|result], ", ")
# => Fabio, 1, 2, 3
%{last_name: name} = registro
# => ** (MatchError) no match of right hand side value: ...
PATTERN MATCHING
(“Regex for non-String”)
a = 1
a = 2
IO.puts a
# => 2
^a = 3
# => ** (MatchError) no match of right hand side value: 3
message = "Hello"
IO.puts message <> " World!"
# => "Hello World!
IO.puts "#{message} World!"
# => "Hello World!
{:a, "b", 67, true}
[:a, "b", 67, true]
%{a: 1, b: 2, c: 3}
[a: 1, b: 2, c: 3]
# => [{:a, 1}, {:b, 2}, {:c, 3}]
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, 2, 3, 4 ... 98, 99, 100]
interval = Enum.slice(range, 30, 10)
# => [31, 32, 33, 34, 35, 36, 37, 38, 39, 40]
evens = Enum.filter(interval, fn(n) -> rem(n, 2) == 0 end)
# => [32, 34, 36, 38, 40]
multiplied = Enum.map(evens, fn(n) -> n * 10 end)
# => [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),
fn(n) -> rem(n, 2) == 0 end
),
fn(n) -> n * 10 end
), 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(fn(n) -> rem(n, 2) end)
|> Enum.map(fn(n) -> n * 10 end)
|> Enum.take(2)
(1..100)
|> Enum.slice(30, 10)
|> Enum.filter(&(rem(&1, 2)))
|> Enum.map(&(&1 * 10))
|> Enum.take(2)
(1..100)
|> Enum.slice(30, 10)
|> Enum.filter(fn(n) -> rem(n, 2) end)
|> Enum.map(fn(n) -> n * 10 end)
|> Enum.take(2)
PIPE OPERATOR
|>
function = fn -> IO.puts("Hello from function") end
function.()
# => Hello from function
pid = spawn(function)
# => Hello from function
Process.alive?(pid)
# => false
Process.alive?(self)
# => true
pid = spawn(fn ->
receive do
{:say, from} ->
send(from, "say what?")
_ ->
Process.exit(self, :normal)
end
end)
Process.alive?(pid)
# => true
send(pid, {:say, self})
receive do
message ->
IO.puts("Recebido: " <> message)
end
# => Recebido: say what?
send(pid, "blabla")
Process.alive?(pid)
# => false
“PROCESSES”
Lightweight
Isolated
Message passing
Mailbox
Garbage Collected
pid = spawn(fn -> ... end)
Process.exit(pid, :kill)
pid = spawn_link(fn ->
receive do
{:say, from} ->
send(from, "say what?")
_ ->
Process.exit(self, :normal)
end
end)
send(pid, "blabla")
** (EXIT from #PID<0.47.0>) killed
pid = spawn_link(fn -> ... end)
Process.exit(pid, :kill)
pid = spawn_link(fn ->
receive do
{:say, from} ->
send(from, "say what?")
_ ->
Process.exit(self, :normal)
end
end)
Process.flag(:trap_exit, true)
send(pid, "blabla")
receive do
{:EXIT, _pid, reason} ->
IO.puts("Motivo do crash: #{reason}")
end
# => Motivo do crash: normal
ASYNCHRONOUS
EXCEPTIONS
(spawn_link, flag, exit)
“GLOBALS”
Javascript
Scala
Go
Clojure
...
defmodule Stack do
def start_link do
Agent.start_link(fn -> [] end,
name: __MODULE__)
end
def pop do
Agent.get_and_update(__MODULE__,
fn(state) ->
[head|tail] = state
{head, tail}
end)
end
def push(new_value) do
Agent.update(__MODULE__,
fn(state) ->
[new_value|state]
end)
end
end
Stack.start_link
Stack.push "hello"
Stack.push "world"
Stack.pop
# => world
Stack.pop
# => hello
Process.list |> Enum.reverse |> Enum.at(0) |> Process.exit(:kill)
Stack.push "foo"
# => ** (exit) exited in: GenServer.call(Stack, {:update, ...,
5000)
# ** (EXIT) no process
# (elixir) lib/gen_server.ex:564: 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
Stack.Supervisor.start_link
Stack.push "hello"
Stack.push "world"
Stack.pop
# => world
Stack.pop
# => hello
Process.list |> Enum.reverse |> Enum.at(0) |> Process.exit(:kill)
Stack.push "foo"
Stack.push "bla"
Stack.pop
# => bla
Stack.pop
# => foo
Stack.Supervisor.start_link
Process.list |> Enum.reverse |> Enum.at(0) |> Process.exit(:kill)
“YOCTO” SERVICES
(micro > nano > pico > femto > atto > zepto > yocto>
APRENDENDO
OBRIGADO!
Perguntas?
@akitaonrails

More Related Content

What's hot

Let's golang
Let's golangLet's golang
Let's golang
SuHyun Jeon
 
PubNative Tracker
PubNative TrackerPubNative Tracker
PubNative Tracker
Andrew Djoga
 
FPBrno 2018-05-22: Benchmarking in elixir
FPBrno 2018-05-22: Benchmarking in elixirFPBrno 2018-05-22: Benchmarking in elixir
FPBrno 2018-05-22: Benchmarking in elixir
Functional Programming Brno
 
Python Tidbits
Python TidbitsPython Tidbits
Python Tidbits
Mitchell Vitez
 
ECMAScript 6 new features
ECMAScript 6 new featuresECMAScript 6 new features
ECMAScript 6 new features
GephenSG
 
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
Phillip Trelford
 
Part2 from math import * from simpson import * k=1 def f(x): return (exp(-(x...
Part2 from math import * from simpson import *  k=1 def f(x): return (exp(-(x...Part2 from math import * from simpson import *  k=1 def f(x): return (exp(-(x...
Part2 from math import * from simpson import * k=1 def f(x): return (exp(-(x...
hwbloom25
 
Javascript - The basics
Javascript - The basicsJavascript - The basics
Javascript - The basics
Bruno Paulino
 
[EN] Ada Lovelace Day 2014 - Tampon run
[EN] Ada Lovelace Day 2014  - Tampon run[EN] Ada Lovelace Day 2014  - Tampon run
[EN] Ada Lovelace Day 2014 - Tampon run
Maja Kraljič
 
Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my day
Tor Ivry
 
Introduction to jRuby
Introduction to jRubyIntroduction to jRuby
Introduction to jRuby
Adam Kalsey
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?
Adam Dudczak
 
The Lesser Known Features of ECMAScript 6
The Lesser Known Features of ECMAScript 6The Lesser Known Features of ECMAScript 6
The Lesser Known Features of ECMAScript 6
Bryan Hughes
 
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
akaptur
 
Perl 5.10 on OSDC.tw 2009
Perl 5.10 on OSDC.tw 2009Perl 5.10 on OSDC.tw 2009
Perl 5.10 on OSDC.tw 2009
scweng
 
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonByterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
akaptur
 
Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)
hasan0812
 
大量地区化解决方案V5
大量地区化解决方案V5大量地区化解决方案V5
大量地区化解决方案V5
bqconf
 
Go a crash course
Go   a crash courseGo   a crash course
Go a crash course
Eleanor McHugh
 
The groovy puzzlers (as Presented at Gr8Conf US 2014)
The groovy puzzlers (as Presented at Gr8Conf US 2014)The groovy puzzlers (as Presented at Gr8Conf US 2014)
The groovy puzzlers (as Presented at Gr8Conf US 2014)
GroovyPuzzlers
 

What's hot (20)

Let's golang
Let's golangLet's golang
Let's golang
 
PubNative Tracker
PubNative TrackerPubNative Tracker
PubNative Tracker
 
FPBrno 2018-05-22: Benchmarking in elixir
FPBrno 2018-05-22: Benchmarking in elixirFPBrno 2018-05-22: Benchmarking in elixir
FPBrno 2018-05-22: Benchmarking in elixir
 
Python Tidbits
Python TidbitsPython Tidbits
Python Tidbits
 
ECMAScript 6 new features
ECMAScript 6 new featuresECMAScript 6 new features
ECMAScript 6 new features
 
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
 
Part2 from math import * from simpson import * k=1 def f(x): return (exp(-(x...
Part2 from math import * from simpson import *  k=1 def f(x): return (exp(-(x...Part2 from math import * from simpson import *  k=1 def f(x): return (exp(-(x...
Part2 from math import * from simpson import * k=1 def f(x): return (exp(-(x...
 
Javascript - The basics
Javascript - The basicsJavascript - The basics
Javascript - The basics
 
[EN] Ada Lovelace Day 2014 - Tampon run
[EN] Ada Lovelace Day 2014  - Tampon run[EN] Ada Lovelace Day 2014  - Tampon run
[EN] Ada Lovelace Day 2014 - Tampon run
 
Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my day
 
Introduction to jRuby
Introduction to jRubyIntroduction to jRuby
Introduction to jRuby
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?
 
The Lesser Known Features of ECMAScript 6
The Lesser Known Features of ECMAScript 6The Lesser Known Features of ECMAScript 6
The Lesser Known Features of ECMAScript 6
 
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
 
Perl 5.10 on OSDC.tw 2009
Perl 5.10 on OSDC.tw 2009Perl 5.10 on OSDC.tw 2009
Perl 5.10 on OSDC.tw 2009
 
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonByterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
 
Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)
 
大量地区化解决方案V5
大量地区化解决方案V5大量地区化解决方案V5
大量地区化解决方案V5
 
Go a crash course
Go   a crash courseGo   a crash course
Go a crash course
 
The groovy puzzlers (as Presented at Gr8Conf US 2014)
The groovy puzzlers (as Presented at Gr8Conf US 2014)The groovy puzzlers (as Presented at Gr8Conf US 2014)
The groovy puzzlers (as Presented at Gr8Conf US 2014)
 

Similar to Elixir - Tolerância a Falhas para Adultos - Secot VIII Sorocaba

Elixir -Tolerância a Falhas para Adultos - GDG Campinas
Elixir  -Tolerância a Falhas para Adultos - GDG CampinasElixir  -Tolerância a Falhas para Adultos - GDG Campinas
Elixir -Tolerância a Falhas para Adultos - GDG Campinas
Fabio Akita
 
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
Nguyen Thi Lan Phuong
 
An introduction to Ruby
An introduction to RubyAn introduction to Ruby
An introduction to Ruby
Wes Oldenbeuving
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
André Faria Gomes
 
PythonOOP
PythonOOPPythonOOP
PythonOOP
Veera Pendyala
 
GE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingGE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python Programming
Muthu Vinayagam
 
Java VS Python
Java VS PythonJava VS Python
Java VS Python
Simone Federici
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
Scott Leberknight
 
Basics
BasicsBasics
Developer Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duoDeveloper Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duo
The Software House
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a Elixir
Svet Ivantchev
 
Erlang bootstrap course
Erlang bootstrap courseErlang bootstrap course
Erlang bootstrap course
Martin Logan
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
AllsoftSolutions
 
Elixir cheatsheet
Elixir cheatsheetElixir cheatsheet
Elixir cheatsheet
Héla Ben Khalfallah
 
Ruby - Uma Introdução
Ruby - Uma IntroduçãoRuby - Uma Introdução
Ruby - Uma Introdução
Ígor Bonadio
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with Python
Han Lee
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
Arturo Herrero
 
Python From Scratch (1).pdf
Python From Scratch  (1).pdfPython From Scratch  (1).pdf
Python From Scratch (1).pdf
NeerajChauhan697157
 
FS2 for Fun and Profit
FS2 for Fun and ProfitFS2 for Fun and Profit
FS2 for Fun and Profit
Adil Akhter
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
Ke Wei Louis
 

Similar to Elixir - Tolerância a Falhas para Adultos - Secot VIII Sorocaba (20)

Elixir -Tolerância a Falhas para Adultos - GDG Campinas
Elixir  -Tolerância a Falhas para Adultos - GDG CampinasElixir  -Tolerância a Falhas para Adultos - GDG Campinas
Elixir -Tolerância a Falhas para Adultos - GDG Campinas
 
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
 
An introduction to Ruby
An introduction to RubyAn introduction to Ruby
An introduction to Ruby
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
 
PythonOOP
PythonOOPPythonOOP
PythonOOP
 
GE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingGE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python Programming
 
Java VS Python
Java VS PythonJava VS Python
Java VS Python
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Basics
BasicsBasics
Basics
 
Developer Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duoDeveloper Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duo
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a Elixir
 
Erlang bootstrap course
Erlang bootstrap courseErlang bootstrap course
Erlang bootstrap course
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 
Elixir cheatsheet
Elixir cheatsheetElixir cheatsheet
Elixir cheatsheet
 
Ruby - Uma Introdução
Ruby - Uma IntroduçãoRuby - Uma Introdução
Ruby - Uma Introdução
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with Python
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
Python From Scratch (1).pdf
Python From Scratch  (1).pdfPython From Scratch  (1).pdf
Python From Scratch (1).pdf
 
FS2 for Fun and Profit
FS2 for Fun and ProfitFS2 for Fun and Profit
FS2 for Fun and Profit
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
 

More from Fabio Akita

Devconf 2019 - São Carlos
Devconf 2019 - São CarlosDevconf 2019 - São Carlos
Devconf 2019 - São Carlos
Fabio 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 Languages
Fabio 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 2018
Fabio Akita
 
Desmistificando Blockchains - 20o Encontro Locaweb SP
Desmistificando Blockchains - 20o Encontro Locaweb SPDesmistificando Blockchains - 20o Encontro Locaweb SP
Desmistificando Blockchains - 20o Encontro Locaweb SP
Fabio Akita
 
Desmistificando Blockchains - Insiter Goiania
Desmistificando Blockchains - Insiter GoianiaDesmistificando Blockchains - Insiter Goiania
Desmistificando Blockchains - Insiter Goiania
Fabio Akita
 
Blockchain em 7 minutos - 7Masters
Blockchain em 7 minutos - 7MastersBlockchain em 7 minutos - 7Masters
Blockchain em 7 minutos - 7Masters
Fabio 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 2017
Fabio 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 Ruby
Fabio 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 TI
Fabio Akita
 
THE CONF - Opening Keynote
THE CONF - Opening KeynoteTHE CONF - Opening Keynote
THE CONF - Opening Keynote
Fabio 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 2017
Fabio Akita
 
Desmistificando Mitos de Startups - Sebrae - AP
Desmistificando Mitos de Startups - Sebrae - APDesmistificando Mitos de Startups - Sebrae - AP
Desmistificando Mitos de Startups - Sebrae - AP
Fabio 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 2017
Fabio 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 2017
Fabio 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 Day
Fabio 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 2016
Fabio Akita
 
Premature Optimization 2.0 - Intercon 2016
Premature Optimization 2.0 - Intercon 2016Premature Optimization 2.0 - Intercon 2016
Premature Optimization 2.0 - Intercon 2016
Fabio Akita
 
Conexão Kinghost - Otimização Prematura
Conexão Kinghost - Otimização PrematuraConexão Kinghost - Otimização Prematura
Conexão Kinghost - Otimização Prematura
Fabio 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 Evil
Fabio 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 Evil
Fabio Akita
 

More from 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
 

Recently uploaded

The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 

Recently uploaded (20)

The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 

Elixir - Tolerância a Falhas para Adultos - Secot VIII Sorocaba

  • 1. ELIXIRTolerância a Falhas para Adultos Fabio Akita
  • 3. Rubyconf Brasil 2016 – 23 e 24 de SetembroRubyconf Brasil 2016 – 23 e 24 de Setembro
  • 4. Rubyconf Brasil 2016 – 23 e 24 de SetembroRubyconf Brasil 2016 – 23 e 24 de Setembro
  • 5. Rubyconf Brasil 2016 – 23 e 24 de SetembroRubyconf Brasil 2016 – 23 e 24 de Setembro
  • 6.
  • 7. Chris McCordChris McCord José ValimJosé Valim
  • 8. Joe Armstrong - EricssonJoe Armstrong - Ericsson
  • 9.
  • 10.
  • 11. defmodule Teste do def say(name) do IO.puts("Hello #{name}") end end Teste.say("Fabio") defmodule Teste do @spec say(String.t) def say(name) when is_string(name) do IO.puts "Hello " <> name end end Teste.say "Fabio"
  • 13. -module(teste). -export([qsort/1]). qsort([]) -> []; qsort([Pivot|T]) -> qsort([X||X<-T,X =< Pivot]) ++ [Pivot] ++ qsort([X||X<-T,X > Pivot]). defmodule Teste do def qsort([]), do: [] def qsort([pivot|t]) do qsort(for x <- t, x < pivot, do: x) ++ [pivot] ++ qsort(for x <- t, x >= pivot, do: x) end end
  • 14. 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(0), do: 1 def factorial(n) do n * factorial(n - 1) end end Teste.factorial(10) # => 3628800
  • 16. {:ok, result} = Enum.fetch([1, 2, 3, 4], 3) IO.puts result # => 4 registro = {:ok, %{name: "Fabio", last_name: "Akita"}} {:ok, %{name: name}} = registro IO.puts name # => Fabio registro = %{name: "Fabio", year: 2016, foo: {:ok, [1, 2, 3]}} %{name: name, foo: {:ok, result}} = registro IO.puts Enum.join([name|result], ", ") # => Fabio, 1, 2, 3 %{last_name: name} = registro # => ** (MatchError) no match of right hand side value: ...
  • 18. a = 1 a = 2 IO.puts a # => 2 ^a = 3 # => ** (MatchError) no match of right hand side value: 3 message = "Hello" IO.puts message <> " World!" # => "Hello World! IO.puts "#{message} World!" # => "Hello World! {:a, "b", 67, true} [:a, "b", 67, true] %{a: 1, b: 2, c: 3} [a: 1, b: 2, c: 3] # => [{:a, 1}, {:b, 2}, {:c, 3}]
  • 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) range = (1..100) # => [1, 2, 3, 4 ... 98, 99, 100] interval = Enum.slice(range, 30, 10) # => [31, 32, 33, 34, 35, 36, 37, 38, 39, 40] evens = Enum.filter(interval, fn(n) -> rem(n, 2) == 0 end) # => [32, 34, 36, 38, 40] multiplied = Enum.map(evens, fn(n) -> n * 10 end) # => [320, 340, 360, 380, 400] Enum.take(multiplied, 2) # => [320, 340]
  • 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) Enum.take( Enum.map( Enum.filter( Enum.slice((1..100), 30, 10), fn(n) -> rem(n, 2) == 0 end ), fn(n) -> n * 10 end ), 2 )
  • 21. 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(fn(n) -> rem(n, 2) end) |> Enum.map(fn(n) -> n * 10 end) |> Enum.take(2)
  • 22. (1..100) |> Enum.slice(30, 10) |> Enum.filter(&(rem(&1, 2))) |> Enum.map(&(&1 * 10)) |> Enum.take(2) (1..100) |> Enum.slice(30, 10) |> Enum.filter(fn(n) -> rem(n, 2) end) |> Enum.map(fn(n) -> n * 10 end) |> Enum.take(2)
  • 24. function = fn -> IO.puts("Hello from function") end function.() # => Hello from function pid = spawn(function) # => Hello from function Process.alive?(pid) # => false Process.alive?(self) # => true
  • 25. pid = spawn(fn -> receive do {:say, from} -> send(from, "say what?") _ -> Process.exit(self, :normal) end end) Process.alive?(pid) # => true send(pid, {:say, self}) receive do message -> IO.puts("Recebido: " <> message) end # => Recebido: say what? send(pid, "blabla") Process.alive?(pid) # => false
  • 27. pid = spawn(fn -> ... end) Process.exit(pid, :kill)
  • 28. pid = spawn_link(fn -> receive do {:say, from} -> send(from, "say what?") _ -> Process.exit(self, :normal) end end) send(pid, "blabla") ** (EXIT from #PID<0.47.0>) killed
  • 29. pid = spawn_link(fn -> ... end) Process.exit(pid, :kill)
  • 30. pid = spawn_link(fn -> receive do {:say, from} -> send(from, "say what?") _ -> Process.exit(self, :normal) end end) Process.flag(:trap_exit, true) send(pid, "blabla") receive do {:EXIT, _pid, reason} -> IO.puts("Motivo do crash: #{reason}") end # => Motivo do crash: normal
  • 33. defmodule Stack do def start_link do Agent.start_link(fn -> [] end, name: __MODULE__) end def pop do Agent.get_and_update(__MODULE__, fn(state) -> [head|tail] = state {head, tail} end) end def push(new_value) do Agent.update(__MODULE__, fn(state) -> [new_value|state] end) end end
  • 34. Stack.start_link Stack.push "hello" Stack.push "world" Stack.pop # => world Stack.pop # => hello Process.list |> Enum.reverse |> Enum.at(0) |> Process.exit(:kill) Stack.push "foo" # => ** (exit) exited in: GenServer.call(Stack, {:update, ..., 5000) # ** (EXIT) no process # (elixir) lib/gen_server.ex:564: GenServer.call/3
  • 35. 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
  • 36. Stack.Supervisor.start_link Stack.push "hello" Stack.push "world" Stack.pop # => world Stack.pop # => hello Process.list |> Enum.reverse |> Enum.at(0) |> Process.exit(:kill) Stack.push "foo" Stack.push "bla" Stack.pop # => bla Stack.pop # => foo
  • 37. Stack.Supervisor.start_link Process.list |> Enum.reverse |> Enum.at(0) |> Process.exit(:kill)
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46. “YOCTO” SERVICES (micro > nano > pico > femto > atto > zepto > yocto>
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 53.
  • 54.
  • 55.
  • 56.