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
61
Workshop JSFP - SEMCOMP 2021
anabastos
0
230
Clojure é um Java melhor que Java - Codecon 2021
anabastos
0
120
Clojure 101 - Criciuma Dev
anabastos
0
290
TDC POA - GraphQL
anabastos
1
240
TDC Porto Alegre 2019 - JS Funcional com Ramda
anabastos
0
210
BackEndSP - GraphQL
anabastos
0
200
Git & Github - RLadies
anabastos
1
210
Programaria Summit - Performance FrontEnd
anabastos
1
190
Other Decks in Programming
See All in Programming
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
return文におけるstd::moveについて
onihusube
1
690
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
180
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
530
第5回日本眼科AI学会総会_AIコンテスト_3位解法
neilsaw
0
170
useSyncExternalStoreを使いまくる
ssssota
6
1k
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
2
460
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
1
350
Stackless и stackful? Корутины и асинхронность в Go
lamodatech
0
620
Full stack testing :: basic to basic
up1
1
930
create_tableをしただけなのに〜囚われのuuid編〜
daisukeshinoku
0
240
創造的活動から切り拓く新たなキャリア 好きから始めてみる夜勤オペレーターからSREへの転身
yjszk
1
130
Featured
See All Featured
The Invisible Side of Design
smashingmag
298
50k
Gamification - CAS2011
davidbonilla
80
5.1k
A Tale of Four Properties
chriscoyier
157
23k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
29
2k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
Making Projects Easy
brettharned
116
5.9k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
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