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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Ana Luiza Portello
July 25, 2018
Programming
190
1
Share
7MASTERS Programação Funcional - Javascript Funcional Com Ramda
Ana Luiza Portello
July 25, 2018
More Decks by Ana Luiza Portello
See All by Ana Luiza Portello
Clojure BR - Brazilian Utils: Simplificando o caos brasileiro com Clojure em uma biblioteca open source
anabastos
0
12
FRONTIN | Elas Programam - Programação Funcional no Front-end
anabastos
0
130
Workshop JSFP - SEMCOMP 2021
anabastos
0
310
Clojure é um Java melhor que Java - Codecon 2021
anabastos
0
180
Clojure 101 - Criciuma Dev
anabastos
0
360
TDC POA - GraphQL
anabastos
1
310
TDC Porto Alegre 2019 - JS Funcional com Ramda
anabastos
0
290
BackEndSP - GraphQL
anabastos
0
270
Git & Github - RLadies
anabastos
1
270
Other Decks in Programming
See All in Programming
関係性から理解する"同一性"の型用語たち
pvcresin
2
630
密結合なバックエンドから TypeScript のコードを生成する
kemuridama
1
710
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
240
AIとASP.NET Coreで雑Webアプリを作った話
mayuki
0
280
AI時代の仕事技芸論 — ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ
kuranuki
1
610
Signal Forms: Beyond the Basics @ngBaguette 2026 in Paris
manfredsteyer
PRO
0
220
These Five Tricks Can Make Your Apps Greener, Cheaper, & Nicer
hollycummins
0
270
ビジネスモデルから紐解く、AI+型駆動開発
hirokiomote
2
5.2k
GitHub Copilot CLIのいいところ
htkym
2
1.3k
Inside Stream API
skrb
1
630
ReactとSvelteのその先、Ripple-TS / Beyond React and Svelte: Ripple-TS
ssssota
3
2k
Make SRE Operations Easier with Azure SRE Agent
kkamegawa
0
3.6k
Featured
See All Featured
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.9k
How to build a perfect <img>
jonoalderson
1
5.6k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
180
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.4k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
560
sira's awesome portfolio website redesign presentation
elsirapls
0
270
Bash Introduction
62gerente
615
210k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
190
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Everyday Curiosity
cassininazir
0
220
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