Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
7MASTERS Programação Funcional - Javascript Fun...
Search
Ana Luiza Portello
July 25, 2018
Programming
1
170
7MASTERS Programação Funcional - Javascript Funcional Com Ramda
Ana Luiza Portello
July 25, 2018
Tweet
Share
More Decks by Ana Luiza Portello
See All by Ana Luiza Portello
FRONTIN | Elas Programam - Programação Funcional no Front-end
anabastos
0
54
Workshop JSFP - SEMCOMP 2021
anabastos
0
220
Clojure é um Java melhor que Java - Codecon 2021
anabastos
0
100
Clojure 101 - Criciuma Dev
anabastos
0
280
TDC POA - GraphQL
anabastos
1
230
TDC Porto Alegre 2019 - JS Funcional com Ramda
anabastos
0
190
BackEndSP - GraphQL
anabastos
0
190
Git & Github - RLadies
anabastos
1
200
Programaria Summit - Performance FrontEnd
anabastos
1
190
Other Decks in Programming
See All in Programming
GenU導入でCDKに初挑戦し、悪戦苦闘した話
hideg
0
160
A New Era of Testing
mannodermaus
2
510
エンジニア1年目で複雑なコードの改善に取り組んだ話
mtnmr
3
2k
Prompt Cachingは本当に効果的なのか検証してみた.pdf
ttnyt8701
0
530
全部見せます! クラシルリワードのSwiftTesting移行プロジェクト
uetyo
0
210
The Shape of a Service Object
inem
0
520
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
0
110
Rubyとクリエイティブコーディングの輪の広がり / The Growing Circle of Ruby and Creative Coding
chobishiba
1
270
【TID2024】模擬講義:プログラマと一緒にゲームをデザインしてみよう!
akatsukigames_tech
0
650
LangChainでWebサイトの内容取得やGitHubソースコード取得
shukob
0
160
GraphQL あるいは React における自律的なデータ取得について
quramy
11
3k
REXML改善のその後
naitoh
0
190
Featured
See All Featured
Bash Introduction
62gerente
608
210k
Writing Fast Ruby
sferik
623
60k
Ruby is Unlike a Banana
tanoku
96
11k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
29
2.6k
YesSQL, Process and Tooling at Scale
rocio
167
14k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Teambox: Starting and Learning
jrom
131
8.7k
Practical Orchestrator
shlominoach
185
10k
What's in a price? How to price your products and services
michaelherold
242
11k
From Idea to $5000 a Month in 5 Months
shpigford
379
46k
Why You Should Never Use an ORM
jnunemaker
PRO
53
8.9k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
32k
Transcript
ANA LUIZA BASTOS github.com/anabastos @naluhh @anapbastos Software Developer na Quanto
e cientista da computação na PUC-SP anabastos.me
JAVASCRIPT FUNCIONAL COM RAMDA
JS pode ser usado como uma linguagem funcional?
Javascript tem funções de primeira ordem (HOF)
Quando falamos de funcional nessas linguagens falamos de “Mantenabilidade” “Menos
bugs” “Declaratividade”
JS vem aos poucos adotando elementos de linguagens funcionais
PROPOSALS
Flatmap Partial Application Pipeline operator Pattern Matching
RAMDA
Biblioteca que foi pensada para tornar mais fácil o javascript
funcional
• 100% imutável • ganho em performance • legibilidade •
point-free / tacit programming
• Lists(map, filter, reduce, contains, replace, passAll, crop, flatten, find)
• Maths(inc, add, mean, sum) • String(split, replace) • Logics(equals, cond, not) • Relation(intersection, clamp, gt, lt) • Functions(curry, pipe, compose, ifElse, etc)
TODAS AS FUNÇÕES SÃO CURRIED
const add = (x, y) => x + y add(1,
2); // 3 add(1) // Error
const add = x => y => x + y
add(1, 2); // 3 add(1) // Function
R.add(1, 2); // 3 R.add(1) // Function
CURRY (PROPOSAL PARTIAL APPLICATION)
const curryAdd = R.curry((x, y) => x + y)) curryAdd(1,
2); // 3 curryAdd(1)(2); // 3
PIPE / COMPOSE (PROPOSAL PIPELINE OPERATOR)
PIPE / COMPOSE: compõe funções de forma sequencial function1 function2
INPUT OUTPUT
EXEMPLINHO
Happy Hour: • Soma o consumido • Adiciona os 10%
• Divide entre os colegas
const conta = [9, 9, 9, 9, 15]
const divideConta = R.pipe( R.sum, // 51 R.mul(1.1), // 56,1
R.divide(6) // 9,35 ) divideConta(conta)
PIPE COMPOSE
const ListOfItems = R.compose( Box, List, ListItems )([{...}, {...}, {...}])
PIPEP / COMPOSEP
then().then().then().then()
const asyncStuff = R.pipeP( getId, getUserById, asyncStuff ) // Promise
IFELSE (maybe monad)
const findName = R.ifElse( R.has('name'), R.prop('name'), R.always('no name'), )({ id:
123, name: “ana”}) // “ana”
FLATTER (PROPOSAL FLATMAP)
R.flatten([1, 2, [3, 4], 5, [6, [7, 8, [9, 12]]]]);
// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
DATA HANDLING
EVOLVE
{ name: “Ana” email: “
[email protected]
”, phone: “11 98698-3010”, address: “rua
da aparecida 304 apt34 ”, }
R.evolve({ email: R.toLower, phone: R.replace(‘-’, ‘’), })(data) // { //
name: “Ana” // email: “
[email protected]
”, // phone: “11 9869983010” // address: ... // }
APPLY SPEC
const createObj = R.applySpec({ counter: R.inc, userData: { phone: R.trim},
}) createObj(0, “ 98499-1900”) // {1, userData{ phone: “9849919000”}}
TryCatch Cond Memoization Lenses
BOM TOOLBOX
COOKBOOK
• Rambda - github.com/selfrefactor/rambda • Ramda-fantasy - github.com/ramda/ramda-fantasy • Thinking
Ramda - randycoulman.com/blog/2016/05/24/thinking-in-ramda-getting -started • Ramda - Derek Stavis(Pagar.me talks)
OBRIGADA :) speakerdeck.com/anabastos anabastos.me github.com/anabastos @naluhh @anapbastos