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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Ana Luiza Portello
July 25, 2018
Programming
1
180
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
120
Workshop JSFP - SEMCOMP 2021
anabastos
0
300
Clojure é um Java melhor que Java - Codecon 2021
anabastos
0
170
Clojure 101 - Criciuma Dev
anabastos
0
340
TDC POA - GraphQL
anabastos
1
290
TDC Porto Alegre 2019 - JS Funcional com Ramda
anabastos
0
270
BackEndSP - GraphQL
anabastos
0
260
Git & Github - RLadies
anabastos
1
260
Programaria Summit - Performance FrontEnd
anabastos
1
240
Other Decks in Programming
See All in Programming
Honoを使ったリモートMCPサーバでAIツールとの連携を加速させる!
tosuri13
1
170
CSC307 Lecture 07
javiergs
PRO
0
550
フロントエンド開発の勘所 -複数事業を経験して見えた判断軸の違い-
heimusu
7
2.8k
インターン生でもAuth0で認証基盤刷新が出来るのか
taku271
0
190
AI巻き込み型コードレビューのススメ
nealle
0
120
Grafana:建立系統全知視角的捷徑
blueswen
0
330
AWS re:Invent 2025参加 直前 Seattle-Tacoma Airport(SEA)におけるハードウェア紛失インシデントLT
tetutetu214
2
100
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
300
AI Agent Tool のためのバックエンドアーキテクチャを考える #encraft
izumin5210
6
1.8k
Fluid Templating in TYPO3 14
s2b
0
130
Vibe Coding - AI 驅動的軟體開發
mickyp100
0
170
HTTPプロトコル正しく理解していますか? 〜かわいい猫と共に学ぼう。ฅ^•ω•^ฅ ニャ〜
hekuchan
2
680
Featured
See All Featured
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2k
GitHub's CSS Performance
jonrohan
1032
470k
Design in an AI World
tapps
0
140
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.3k
Skip the Path - Find Your Career Trail
mkilby
0
53
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
0
1.1k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
196
71k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
0
100
Utilizing Notion as your number one productivity tool
mfonobong
3
220
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
0
250
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
200
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
440
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