Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Programação Funcional & Elixir
Search
Amanda
November 04, 2017
Technology
150
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Programação Funcional & Elixir
Amanda
November 04, 2017
Transcript
56 slides
Programação Funcional & Elixir
@amandasposito @amsposito @amandasposito
None
Falando um pouco de história
http://www.gotw.ca/publications/concurrency-ddj.htm
None
None
“Efficiency and performance optimization will get more, not less, important.”
“Applications will increasingly need to be concurrent if they want
to fully exploit continuing exponential CPU throughput gains.”
Por que isso afeta nossa aplicação?
None
Elixir criada por José Valim
Percebeu que as ferramentas que existiam não eram boas para
concorrência
None
Elixir roda em cima da maquina virtual do Erlang
Erlang é conhecido por rodar aplicações com latência baixa, distribuídas
ou tolerante a falhas
Escalabilidade Tolerância a falhas Compatível com Erlang Hot Code Swap
Linguagem Dinâmica Metaprogramação Polimorfismo Concorrência
Diferentes paradigmas
Paradigma Funcional
–Introduction to Functional Programming - Richard Bird Philip Wadler “Programming
in a functional language consists of building definitions and using the computer to evaluate expressions.”
Imutabilidade
Consistência de dados
Concorrência Capacidade de lidar com várias coisas ao mesmo tempo
https://blog.whatsapp.com/196/1-million-is-so-2011?
Vamos resolver um problema
None
None
switch = fn (bulb) -> ... end switch.(bulb)
defmodule LightBulb do def switch(human, bulb) do end end LightBulb.switch(bulb)
Pattern Matching
name = "Amanda"
Interactive Elixir (1.5.2) - press Ctrl+C to exit (type h()
ENTER for help) iex(1)> name = "Amanda" "Amanda" iex(2)> "Amanda" = name "Amanda" iex(3)> "Amanda S" = name ** (MatchError) no match of right hand side value: "Amanda"
defmodule LightBulb do def switch(human = %Human{}, bulb = %Bulb{})
… end end
Function Arity
defmodule LightBulb do def switch(human, bulb) do ... end def
switch(_) do IO.puts "Precisamos de um humano e de uma escada." end end
Guards
defmodule LightBulb do def switch(human, bulb) when bulb.burned_out == true
do … end end
If and unless
defmodule LightBulb do def switch(human, bulb) when bulb.burned_out == true
do ladder = Ladder.get_average_height() if ladder.under do … end end end
Pipe Operator
new_bulb = Bulb.get_bulb() lader = Ladder.get_average_height() human = Human.climb(human, ladder)
human = Human.remove_bulb(human, bulb) human = Human.put_bulb(human, new_bulb)
Ladder.get_average_height() |> Human.climb(human) |> Human.remove_bulb(bulb) |> Human.put_bulb(new_bulb)
None
Recursão
numbers = 3; for(i = numbers; i > 0; i--)
{ console.log(i); }
None
defmodule NaturalNums do # Uma clausula para parar a recursão
def print(1), do: IO.puts(1) def print(n) do # Imprime o número" IO.puts(n) # Chama a si mesmo com um valor a menos print(n - 1) end end
iex(1)> NaturalNums.print(3) 3 2 1 :ok
None
None
https://www.codeschool.com/courses/try-elixir
https://www.dailydrip.com/topics/elixir https://github.com/dailydrip/firestorm
http://plataformatec.com.br/elixir-radar
None
Obrigada!
Referências • https://hipsters.tech/elixir-a-linguagem-hipster- hipsters-48/ • https://codewords.recurse.com/issues/one/an- introduction-to-functional-programming • http://theerlangelist.blogspot.com.br/2013/05/working- with-immutable-data.html
More Decks by Amanda
See All by Amanda
Lessons Learned From an Elixir OTP Project
amandasposito
2
110
Aprendizados de um projeto Elixir OTP
amandasposito
4
660
SOLID - Dependency inversion principle
amandasposito
0
110
Como concorrência funciona em Elixir?
amandasposito
1
250
Ecto, você sabe o que é ?
amandasposito
4
260
Novidades no Rails 5
amandasposito
0
110
Rails Engines & RSpec
amandasposito
0
260
Elixir e Phoenix
amandasposito
3
600
Elixir em 5 minutos
amandasposito
1
110
Other Decks in Technology
See All in Technology
異夢同船〜異なる夢でも同じ船でなんとかする〜
fortegp05
1
460
個人ASを取得して、自宅Kubernetes上のVMをグローバルIPで公開した話
munenick
0
140
DevOps Agentにあらゆるセキュリティインシデントのトリアージを任せた件
jirtosterone
1
170
目を覚ませ!僕らの認証情報が何者かに侵略されてるぞ
tkito
2
430
おうち環境でも「なるべく止めたくない!」 ― おうち環境の機器冗長化の理想と現実
yuutosi
1
520
人の努力に頼らないセキュリティをエンジニアリングする在り方 / An approach to engineering security that does not rely on human effort
carta_engineering
0
160
契約書SaaSにAIエージェントを組み込む
sansantech
PRO
0
170
20261113_JAWS_Osaka
takuyay0ne
0
570
これからのデータエンジニアの役割について考える / Rethinking the Role of Data Engineers in the AI Era
okiyuki99
0
530
速くなるほど、深く考える AI時代のQAに学ぶ
kobayashiyorimitsu
0
250
SSFの現在地 ― CAEP/RISCからAI Identityへ
oidfj
0
460
WasmをRustにする技術
sansantech
PRO
0
110
Featured
See All Featured
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.8k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.8k
The Curse of the Amulet
leimatthew05
4
17k
Typedesign – Prime Four
hannesfritz
42
3.2k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
330
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
570
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
620
A designer walks into a library…
pauljervisheath
211
25k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
370
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.4k
The Limits of Empathy - UXLibs8
cassininazir
2
790
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
340