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
7MASTERS Programação Funcional - Javascript Fun...
Search
Ana Luiza Portello
July 25, 2018
Programming
200
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
51
FRONTIN | Elas Programam - Programação Funcional no Front-end
anabastos
0
150
Workshop JSFP - SEMCOMP 2021
anabastos
0
320
Clojure é um Java melhor que Java - Codecon 2021
anabastos
0
200
Clojure 101 - Criciuma Dev
anabastos
0
380
TDC POA - GraphQL
anabastos
1
320
TDC Porto Alegre 2019 - JS Funcional com Ramda
anabastos
0
300
BackEndSP - GraphQL
anabastos
0
280
Git & Github - RLadies
anabastos
1
290
Other Decks in Programming
See All in Programming
baseline으로 마이그레이션, 리팩토링 안전하게 맡기기
fornewid
1
910
Materialが消えた日 〜真っ白なFlutterキャンバスにRenderObjectで絵を描く〜
umigishiaoi
0
150
プロジェクトコードをキレイキレイしよう!暗黙的な参照を読み解く静的解析
ostk0069
0
210
TanStack Vue Query と Pinia Colada から学ぶ非同期状態の型設計
aoshi
0
620
複数ドメインを一つのアプリに統合するFlutterの設計と運用_FlutterKaigi2026登壇資料(須永高弘)
takahirosunaga
0
160
AmebaブログはKMPから卒業します
kmars0605
0
330
小さなアプリを作って公開するまで
onozaty
0
130
Kawaiicon: Kubernetes, it's no longer cool, but let's secure it anyway!
barnbarn
0
110
React Native経験者が Flutterを30⽇間触って驚いたこと
3saito
0
160
そのデザイントークン、Flutterでも同じ見た目になりますか?
nakamizu
0
310
SFCで実現する病院・医療システムの動的組み立て式UI
koukimiura
1
170
クラウドゲーミングのパフォーマンス最適化に挑む / Cloud Gaming Performance Tuning
vivion
0
330
Featured
See All Featured
Accessibility Awareness
sabderemane
1
290
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
Tell your own story through comics
letsgokoyo
1
1.1k
The Curious Case for Waylosing
cassininazir
1
610
The agentic SEO stack - context over prompts
schlessera
0
1k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
880
The Language of Interfaces
destraynor
162
27k
WENDY [Excerpt]
tessaabrams
14
40k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
1
300
Music & Morning Musume
bryan
48
7.5k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
2
3k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.9k
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