SlideShare a Scribd company logo
1 of 24
Download to read offline
Ramda
let's write declarative js
Roman Rodych
Innocode
What this talk about?
Approaches
Motivation (why?)
What we want?
● Describe what to do instead of how
● Avoid duplication
● Stop reinventing common functionality
● Composition
● Less code - less bugs))
Solutions (how?)
Accept functions as arguments
[1, 2, 3].map(function (x) {
return -x
})
Return function as result
function fn (a, b) {
return a + b
}.bind(undefined, 1, 2) // => fn(1, 2)
Higher order functions
Currying
var add = R.curry(function (x, y) {
return x + y
})
add(4, 2) // 6
add(4)(2) // 6
var add4 = add(4) // fn !
add4(2) // 6
add() // fn !
Function first, data last
var data = [ {id: 1, price: “33.00”, amount: 798},
{id: 5, price: “22.00”, amount: 0}, … ]
// Our task is to get all sold products
var getProducts = R.filter(
R.propEq(“amount”, 0)
) // (list) => list.filter( (item) => item.amount === 0 )
getProducts(data) // [{id: 5, price: “22.00”, amount: 0}, ...]
Dictionary for the next slide
R.pipe - Performs left-to-right function composition. The leftmost function may
have any arity; the remaining functions must be unary.
R.prop - Returns a function that when supplied an object returns the indicated
property of that object, if it exists.
R.__ - A special placeholder value used to specify "gaps" within curried functions,
allowing partial application of any combination of arguments, regardless of their
positions.
R.gt - (a, b) => a > b
Functions composition e.g.: pipe, compose...
var data = [ {id: 1, price: “150.00”, amount: 798},
{id: 5, price: “22.00”, amount: 0}, … ]
// Now task is to get “id” and “price” of all available and
expansive products
var available = R.pipe(R.prop(“amount”), R.gt(R.__, 0))
// (item) => item.amount > 0
var expansive = R.pipe(R.prop(“price”), parseFloat, R.gt(R.__, 100))
// (item) => parseFloat(item.price) > 100
...
Functions composition II
var data = [ {id: 1, price: “150.00”, amount: 798},
{id: 5, price: “22.00”, amount: 0}, … ]
...
var filterProducts = R.filter(
R.allPass([available, expansive]))
var getProducts = R.pipe( filterProducts, R.pick([“id”, “price”]) )
getProducts(data) // [{id: 1, price: “150.00”, amount: 798}, ...]
Point free - function evolution
Past (dark ages)
function makeMeHappy() {
b = a + 42 // a and b are somewhere in the scope
}
Present (renaissance)
const makeMeHappy = a => a + 42
Future (post-postmodernism but nobody knows, really...)
const makeMeHappy = R.add(42)
Dictionary for next slide
R.converge - Boring long definition…
R.find - Returns the first element of the list which matches the predicate
R.nthArg - Returns a function which returns its nth argument
Point free II “overrefactoring”
var numberPropGt = R.curryN(3, R.
converge(
R.gt,
[ R.pipe(
R.converge(R.prop,
[R.nthArg(0),
R.nthArg(2) ]),
parseFloat ),
R.nthArg(1)
]
))
var available = numberPropGt(“amount”, 0)
// (item) => parseFloat(item.amount) > 0
var expansive = numberPropGt(“price”, 100)
// (item) => parseFloat(item.price) > 100
...
Point free III real example
// findById :: String -> Array -> Object
const findById = R.converge(
R.find,
[
R.pipe(R.nthArg(0), R.propEq("id")),
R.nthArg(1)
]
)
Price $$$
● easy
● fast
● lightNot so
Should you? (when?)
When to use
● DSLs
● Rich business logic handlers
● Your option...
Useful info
● ramdajs.com
● github.com/MostlyAdequate/mostly-adequate-guide
● youtube.com/channel/UCKjVLbSDoM-8-eEM7A30igA
● youtube.com/watch?v=m3svKOdZijA
● sitepoint.com/functional-programming-techniques-with-ruby-part-i
● github.com/solnic/transproc
Alternatives (what else?)
You can try
● purescript.org
● fitzgen.github.io/wu.js
● lodash.com
Thanks! Maybe(“applauds”)
Beer time!

More Related Content

What's hot

LinkedIn TBC JavaScript 100: Functions
 LinkedIn TBC JavaScript 100: Functions LinkedIn TBC JavaScript 100: Functions
LinkedIn TBC JavaScript 100: FunctionsAdam Crabtree
 
Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)David de Boer
 
ITT 2015 - Saul Mora - Object Oriented Function Programming
ITT 2015 - Saul Mora - Object Oriented Function ProgrammingITT 2015 - Saul Mora - Object Oriented Function Programming
ITT 2015 - Saul Mora - Object Oriented Function ProgrammingIstanbul Tech Talks
 
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur..."How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...Fwdays
 
Simplifying java with lambdas (short)
Simplifying java with lambdas (short)Simplifying java with lambdas (short)
Simplifying java with lambdas (short)RichardWarburton
 
JavaScript Functions
JavaScript FunctionsJavaScript Functions
JavaScript FunctionsBrian Moschel
 
Java8 stream
Java8 streamJava8 stream
Java8 streamkoji lin
 
Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察Tsuyoshi Yamamoto
 
Let's build a parser!
Let's build a parser!Let's build a parser!
Let's build a parser!Boy Baukema
 
Functional programming in javascript
Functional programming in javascriptFunctional programming in javascript
Functional programming in javascriptBoris Burdiliak
 
Hello Swift 3/5 - Function
Hello Swift 3/5 - FunctionHello Swift 3/5 - Function
Hello Swift 3/5 - FunctionCody Yun
 
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...John De Goes
 
A swift introduction to Swift
A swift introduction to SwiftA swift introduction to Swift
A swift introduction to SwiftGiordano Scalzo
 
Functional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedFunctional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedSusan Potter
 
Swiftの関数型っぽい部分
Swiftの関数型っぽい部分Swiftの関数型っぽい部分
Swiftの関数型っぽい部分bob_is_strange
 
Thinking Functionally with JavaScript
Thinking Functionally with JavaScriptThinking Functionally with JavaScript
Thinking Functionally with JavaScriptLuis Atencio
 

What's hot (20)

LinkedIn TBC JavaScript 100: Functions
 LinkedIn TBC JavaScript 100: Functions LinkedIn TBC JavaScript 100: Functions
LinkedIn TBC JavaScript 100: Functions
 
Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)
 
ITT 2015 - Saul Mora - Object Oriented Function Programming
ITT 2015 - Saul Mora - Object Oriented Function ProgrammingITT 2015 - Saul Mora - Object Oriented Function Programming
ITT 2015 - Saul Mora - Object Oriented Function Programming
 
Lua Study Share
Lua Study ShareLua Study Share
Lua Study Share
 
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur..."How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
 
Simplifying java with lambdas (short)
Simplifying java with lambdas (short)Simplifying java with lambdas (short)
Simplifying java with lambdas (short)
 
JavaScript Functions
JavaScript FunctionsJavaScript Functions
JavaScript Functions
 
Java8 stream
Java8 streamJava8 stream
Java8 stream
 
Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察
 
Let's build a parser!
Let's build a parser!Let's build a parser!
Let's build a parser!
 
Functional programming in javascript
Functional programming in javascriptFunctional programming in javascript
Functional programming in javascript
 
Hello Swift 3/5 - Function
Hello Swift 3/5 - FunctionHello Swift 3/5 - Function
Hello Swift 3/5 - Function
 
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...
 
A swift introduction to Swift
A swift introduction to SwiftA swift introduction to Swift
A swift introduction to Swift
 
Sneaking inside Kotlin features
Sneaking inside Kotlin featuresSneaking inside Kotlin features
Sneaking inside Kotlin features
 
Swift 2
Swift 2Swift 2
Swift 2
 
Functional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedFunctional Algebra: Monoids Applied
Functional Algebra: Monoids Applied
 
Swiftの関数型っぽい部分
Swiftの関数型っぽい部分Swiftの関数型っぽい部分
Swiftの関数型っぽい部分
 
はじめてのGroovy
はじめてのGroovyはじめてのGroovy
はじめてのGroovy
 
Thinking Functionally with JavaScript
Thinking Functionally with JavaScriptThinking Functionally with JavaScript
Thinking Functionally with JavaScript
 

Viewers also liked

Functional programming in ruby
Functional programming in rubyFunctional programming in ruby
Functional programming in rubyKoen Handekyn
 
Chaining and function composition with lodash / underscore
Chaining and function composition with lodash / underscoreChaining and function composition with lodash / underscore
Chaining and function composition with lodash / underscoreNicolas Carlo
 
WHY JAVASCRIPT FUNCTIONAL PROGRAMMING IS SO HARD?
WHY JAVASCRIPT FUNCTIONAL PROGRAMMING IS SO HARD? WHY JAVASCRIPT FUNCTIONAL PROGRAMMING IS SO HARD?
WHY JAVASCRIPT FUNCTIONAL PROGRAMMING IS SO HARD? reactima
 
Lars thorup-react-and-redux-2016-09
Lars thorup-react-and-redux-2016-09Lars thorup-react-and-redux-2016-09
Lars thorup-react-and-redux-2016-09BestBrains
 
Functional Programming with JavaScript
Functional Programming with JavaScriptFunctional Programming with JavaScript
Functional Programming with JavaScriptWebF
 
Building Component Based Rails Applications. Part 2.
Building Component Based Rails Applications. Part 2.Building Component Based Rails Applications. Part 2.
Building Component Based Rails Applications. Part 2.Pivorak MeetUp
 
Functional Immutable CSS
Functional Immutable CSS Functional Immutable CSS
Functional Immutable CSS Pivorak MeetUp
 
Building component based rails applications. part 1.
Building component based rails applications. part 1.Building component based rails applications. part 1.
Building component based rails applications. part 1.Pivorak MeetUp
 
Права інтелектуальної власності в IT сфері.
Права інтелектуальної власності  в IT сфері.Права інтелектуальної власності  в IT сфері.
Права інтелектуальної власності в IT сфері.Pivorak MeetUp
 
Pivorak Clojure by Dmytro Bignyak
Pivorak Clojure by Dmytro BignyakPivorak Clojure by Dmytro Bignyak
Pivorak Clojure by Dmytro BignyakPivorak MeetUp
 
"Ruby meets Event Sourcing" by Anton Paisov
"Ruby meets Event Sourcing" by Anton Paisov"Ruby meets Event Sourcing" by Anton Paisov
"Ruby meets Event Sourcing" by Anton PaisovPivorak MeetUp
 
Overcommit for #pivorak
Overcommit for #pivorak Overcommit for #pivorak
Overcommit for #pivorak Pivorak MeetUp
 
Trailblazer Introduction by Nick Sutterer
Trailblazer Introduction by Nick SuttererTrailblazer Introduction by Nick Sutterer
Trailblazer Introduction by Nick SuttererPivorak MeetUp
 
Lightweight APIs in mRuby
Lightweight APIs in mRubyLightweight APIs in mRuby
Lightweight APIs in mRubyPivorak MeetUp
 
"5 skills to master" by Alexander Skakunov
"5 skills to master" by Alexander Skakunov"5 skills to master" by Alexander Skakunov
"5 skills to master" by Alexander SkakunovPivorak MeetUp
 
Digital Nomading on Rails
Digital Nomading on RailsDigital Nomading on Rails
Digital Nomading on RailsPivorak MeetUp
 
The Silver Bullet Syndrome by Alexey Vasiliev
The Silver Bullet Syndrome by Alexey VasilievThe Silver Bullet Syndrome by Alexey Vasiliev
The Silver Bullet Syndrome by Alexey VasilievPivorak MeetUp
 

Viewers also liked (20)

Functional programming in ruby
Functional programming in rubyFunctional programming in ruby
Functional programming in ruby
 
Hardcore functional programming
Hardcore functional programmingHardcore functional programming
Hardcore functional programming
 
Chaining and function composition with lodash / underscore
Chaining and function composition with lodash / underscoreChaining and function composition with lodash / underscore
Chaining and function composition with lodash / underscore
 
WHY JAVASCRIPT FUNCTIONAL PROGRAMMING IS SO HARD?
WHY JAVASCRIPT FUNCTIONAL PROGRAMMING IS SO HARD? WHY JAVASCRIPT FUNCTIONAL PROGRAMMING IS SO HARD?
WHY JAVASCRIPT FUNCTIONAL PROGRAMMING IS SO HARD?
 
Lars thorup-react-and-redux-2016-09
Lars thorup-react-and-redux-2016-09Lars thorup-react-and-redux-2016-09
Lars thorup-react-and-redux-2016-09
 
Functional Programming with JavaScript
Functional Programming with JavaScriptFunctional Programming with JavaScript
Functional Programming with JavaScript
 
Building Component Based Rails Applications. Part 2.
Building Component Based Rails Applications. Part 2.Building Component Based Rails Applications. Part 2.
Building Component Based Rails Applications. Part 2.
 
Functional Immutable CSS
Functional Immutable CSS Functional Immutable CSS
Functional Immutable CSS
 
Building component based rails applications. part 1.
Building component based rails applications. part 1.Building component based rails applications. part 1.
Building component based rails applications. part 1.
 
Права інтелектуальної власності в IT сфері.
Права інтелектуальної власності  в IT сфері.Права інтелектуальної власності  в IT сфері.
Права інтелектуальної власності в IT сфері.
 
Espec |> Elixir BDD
Espec |> Elixir BDDEspec |> Elixir BDD
Espec |> Elixir BDD
 
Pivorak Clojure by Dmytro Bignyak
Pivorak Clojure by Dmytro BignyakPivorak Clojure by Dmytro Bignyak
Pivorak Clojure by Dmytro Bignyak
 
"Ruby meets Event Sourcing" by Anton Paisov
"Ruby meets Event Sourcing" by Anton Paisov"Ruby meets Event Sourcing" by Anton Paisov
"Ruby meets Event Sourcing" by Anton Paisov
 
Overcommit for #pivorak
Overcommit for #pivorak Overcommit for #pivorak
Overcommit for #pivorak
 
Trailblazer Introduction by Nick Sutterer
Trailblazer Introduction by Nick SuttererTrailblazer Introduction by Nick Sutterer
Trailblazer Introduction by Nick Sutterer
 
Lightweight APIs in mRuby
Lightweight APIs in mRubyLightweight APIs in mRuby
Lightweight APIs in mRuby
 
"5 skills to master" by Alexander Skakunov
"5 skills to master" by Alexander Skakunov"5 skills to master" by Alexander Skakunov
"5 skills to master" by Alexander Skakunov
 
GIS on Rails
GIS on RailsGIS on Rails
GIS on Rails
 
Digital Nomading on Rails
Digital Nomading on RailsDigital Nomading on Rails
Digital Nomading on Rails
 
The Silver Bullet Syndrome by Alexey Vasiliev
The Silver Bullet Syndrome by Alexey VasilievThe Silver Bullet Syndrome by Alexey Vasiliev
The Silver Bullet Syndrome by Alexey Vasiliev
 

Similar to Ramda lets write declarative js

Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
Functional Programming In Java
Functional Programming In JavaFunctional Programming In Java
Functional Programming In JavaAndrei Solntsev
 
TDC2016SP - Trilha Programação Funcional
TDC2016SP - Trilha Programação FuncionalTDC2016SP - Trilha Programação Funcional
TDC2016SP - Trilha Programação Funcionaltdc-globalcode
 
A Tour of Building Web Applications with R Shiny
A Tour of Building Web Applications with R Shiny A Tour of Building Web Applications with R Shiny
A Tour of Building Web Applications with R Shiny Wendy Chen Dubois
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming iiPrashant Kalkar
 
Composition in JavaScript
Composition in JavaScriptComposition in JavaScript
Composition in JavaScriptJosh Mock
 
Apache Spark - Basics of RDD & RDD Operations | Big Data Hadoop Spark Tutoria...
Apache Spark - Basics of RDD & RDD Operations | Big Data Hadoop Spark Tutoria...Apache Spark - Basics of RDD & RDD Operations | Big Data Hadoop Spark Tutoria...
Apache Spark - Basics of RDD & RDD Operations | Big Data Hadoop Spark Tutoria...CloudxLab
 
R for Pythonistas (PyData NYC 2017)
R for Pythonistas (PyData NYC 2017)R for Pythonistas (PyData NYC 2017)
R for Pythonistas (PyData NYC 2017)Christopher Roach
 
What's in Kotlin for us - Alexandre Greschon, MyHeritage
What's in Kotlin for us - Alexandre Greschon, MyHeritageWhat's in Kotlin for us - Alexandre Greschon, MyHeritage
What's in Kotlin for us - Alexandre Greschon, MyHeritageDroidConTLV
 
Introduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in HaskellIntroduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in Haskellnebuta
 
Introduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in HaskellIntroduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in Haskellnebuta
 

Similar to Ramda lets write declarative js (20)

ProgrammingwithGOLang
ProgrammingwithGOLangProgrammingwithGOLang
ProgrammingwithGOLang
 
Array Cont
Array ContArray Cont
Array Cont
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Spark workshop
Spark workshopSpark workshop
Spark workshop
 
Functional Programming In Java
Functional Programming In JavaFunctional Programming In Java
Functional Programming In Java
 
Python : Functions
Python : FunctionsPython : Functions
Python : Functions
 
25-functions.ppt
25-functions.ppt25-functions.ppt
25-functions.ppt
 
TDC2016SP - Trilha Programação Funcional
TDC2016SP - Trilha Programação FuncionalTDC2016SP - Trilha Programação Funcional
TDC2016SP - Trilha Programação Funcional
 
Haskell 101
Haskell 101Haskell 101
Haskell 101
 
Practical cats
Practical catsPractical cats
Practical cats
 
Monads in Swift
Monads in SwiftMonads in Swift
Monads in Swift
 
A Tour of Building Web Applications with R Shiny
A Tour of Building Web Applications with R Shiny A Tour of Building Web Applications with R Shiny
A Tour of Building Web Applications with R Shiny
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming ii
 
Composition in JavaScript
Composition in JavaScriptComposition in JavaScript
Composition in JavaScript
 
Apache Spark - Basics of RDD & RDD Operations | Big Data Hadoop Spark Tutoria...
Apache Spark - Basics of RDD & RDD Operations | Big Data Hadoop Spark Tutoria...Apache Spark - Basics of RDD & RDD Operations | Big Data Hadoop Spark Tutoria...
Apache Spark - Basics of RDD & RDD Operations | Big Data Hadoop Spark Tutoria...
 
R for Pythonistas (PyData NYC 2017)
R for Pythonistas (PyData NYC 2017)R for Pythonistas (PyData NYC 2017)
R for Pythonistas (PyData NYC 2017)
 
What's in Kotlin for us - Alexandre Greschon, MyHeritage
What's in Kotlin for us - Alexandre Greschon, MyHeritageWhat's in Kotlin for us - Alexandre Greschon, MyHeritage
What's in Kotlin for us - Alexandre Greschon, MyHeritage
 
Elm: give it a try
Elm: give it a tryElm: give it a try
Elm: give it a try
 
Introduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in HaskellIntroduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in Haskell
 
Introduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in HaskellIntroduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in Haskell
 

More from Pivorak MeetUp

Lisp(Lots of Irritating Superfluous Parentheses)
Lisp(Lots of Irritating Superfluous Parentheses)Lisp(Lots of Irritating Superfluous Parentheses)
Lisp(Lots of Irritating Superfluous Parentheses)Pivorak MeetUp
 
Some strange stories about mocks.
Some strange stories about mocks.Some strange stories about mocks.
Some strange stories about mocks.Pivorak MeetUp
 
Business-friendly library for inter-service communication
Business-friendly library for inter-service communicationBusiness-friendly library for inter-service communication
Business-friendly library for inter-service communicationPivorak MeetUp
 
How i was a team leader once
How i was a team leader onceHow i was a team leader once
How i was a team leader oncePivorak MeetUp
 
Rails MVC by Sergiy Koshovyi
Rails MVC by Sergiy KoshovyiRails MVC by Sergiy Koshovyi
Rails MVC by Sergiy KoshovyiPivorak MeetUp
 
Introduction to Rails by Evgeniy Hinyuk
Introduction to Rails by Evgeniy HinyukIntroduction to Rails by Evgeniy Hinyuk
Introduction to Rails by Evgeniy HinyukPivorak MeetUp
 
Ruby OOP (in Ukrainian)
Ruby OOP (in Ukrainian)Ruby OOP (in Ukrainian)
Ruby OOP (in Ukrainian)Pivorak MeetUp
 
Ruby Summer Course by #pivorak & OnApp - OOP Basics in Ruby
Ruby Summer Course by #pivorak & OnApp - OOP Basics in RubyRuby Summer Course by #pivorak & OnApp - OOP Basics in Ruby
Ruby Summer Course by #pivorak & OnApp - OOP Basics in RubyPivorak MeetUp
 
The Saga Pattern: 2 years later by Robert Pankowecki
The Saga Pattern: 2 years later by Robert PankoweckiThe Saga Pattern: 2 years later by Robert Pankowecki
The Saga Pattern: 2 years later by Robert PankoweckiPivorak MeetUp
 
Data and Bounded Contexts by Volodymyr Byno
Data and Bounded Contexts by Volodymyr BynoData and Bounded Contexts by Volodymyr Byno
Data and Bounded Contexts by Volodymyr BynoPivorak MeetUp
 
Successful Remote Development by Alex Rozumii
Successful Remote Development by Alex RozumiiSuccessful Remote Development by Alex Rozumii
Successful Remote Development by Alex RozumiiPivorak MeetUp
 
Origins of Elixir programming language
Origins of Elixir programming languageOrigins of Elixir programming language
Origins of Elixir programming languagePivorak MeetUp
 
Multi language FBP with Flowex by Anton Mishchuk
Multi language FBP with Flowex by Anton Mishchuk Multi language FBP with Flowex by Anton Mishchuk
Multi language FBP with Flowex by Anton Mishchuk Pivorak MeetUp
 
Detective story of one clever user - Lightning Talk By Sergiy Kukunin
Detective story of one clever user - Lightning Talk By Sergiy KukuninDetective story of one clever user - Lightning Talk By Sergiy Kukunin
Detective story of one clever user - Lightning Talk By Sergiy KukuninPivorak MeetUp
 
CryptoParty: Introduction by Olexii Markovets
CryptoParty: Introduction by Olexii MarkovetsCryptoParty: Introduction by Olexii Markovets
CryptoParty: Introduction by Olexii MarkovetsPivorak MeetUp
 
How to make first million by 30 (or not, but tryin') - by Marek Piasecki
How to make first million by 30 (or not, but tryin') - by Marek PiaseckiHow to make first million by 30 (or not, but tryin') - by Marek Piasecki
How to make first million by 30 (or not, but tryin') - by Marek PiaseckiPivorak MeetUp
 
GIS on Rails by Oleksandr Kychun
GIS on Rails by Oleksandr Kychun GIS on Rails by Oleksandr Kychun
GIS on Rails by Oleksandr Kychun Pivorak MeetUp
 
Unikernels - Keep It Simple to the Bare Metal
Unikernels - Keep It Simple to the Bare MetalUnikernels - Keep It Simple to the Bare Metal
Unikernels - Keep It Simple to the Bare MetalPivorak MeetUp
 
HTML Canvas tips & tricks - Lightning Talk by Roman Rodych
 HTML Canvas tips & tricks - Lightning Talk by Roman Rodych HTML Canvas tips & tricks - Lightning Talk by Roman Rodych
HTML Canvas tips & tricks - Lightning Talk by Roman RodychPivorak MeetUp
 

More from Pivorak MeetUp (20)

Lisp(Lots of Irritating Superfluous Parentheses)
Lisp(Lots of Irritating Superfluous Parentheses)Lisp(Lots of Irritating Superfluous Parentheses)
Lisp(Lots of Irritating Superfluous Parentheses)
 
Some strange stories about mocks.
Some strange stories about mocks.Some strange stories about mocks.
Some strange stories about mocks.
 
Business-friendly library for inter-service communication
Business-friendly library for inter-service communicationBusiness-friendly library for inter-service communication
Business-friendly library for inter-service communication
 
How i was a team leader once
How i was a team leader onceHow i was a team leader once
How i was a team leader once
 
Rails MVC by Sergiy Koshovyi
Rails MVC by Sergiy KoshovyiRails MVC by Sergiy Koshovyi
Rails MVC by Sergiy Koshovyi
 
Introduction to Rails by Evgeniy Hinyuk
Introduction to Rails by Evgeniy HinyukIntroduction to Rails by Evgeniy Hinyuk
Introduction to Rails by Evgeniy Hinyuk
 
Ruby OOP (in Ukrainian)
Ruby OOP (in Ukrainian)Ruby OOP (in Ukrainian)
Ruby OOP (in Ukrainian)
 
Testing in Ruby
Testing in RubyTesting in Ruby
Testing in Ruby
 
Ruby Summer Course by #pivorak & OnApp - OOP Basics in Ruby
Ruby Summer Course by #pivorak & OnApp - OOP Basics in RubyRuby Summer Course by #pivorak & OnApp - OOP Basics in Ruby
Ruby Summer Course by #pivorak & OnApp - OOP Basics in Ruby
 
The Saga Pattern: 2 years later by Robert Pankowecki
The Saga Pattern: 2 years later by Robert PankoweckiThe Saga Pattern: 2 years later by Robert Pankowecki
The Saga Pattern: 2 years later by Robert Pankowecki
 
Data and Bounded Contexts by Volodymyr Byno
Data and Bounded Contexts by Volodymyr BynoData and Bounded Contexts by Volodymyr Byno
Data and Bounded Contexts by Volodymyr Byno
 
Successful Remote Development by Alex Rozumii
Successful Remote Development by Alex RozumiiSuccessful Remote Development by Alex Rozumii
Successful Remote Development by Alex Rozumii
 
Origins of Elixir programming language
Origins of Elixir programming languageOrigins of Elixir programming language
Origins of Elixir programming language
 
Multi language FBP with Flowex by Anton Mishchuk
Multi language FBP with Flowex by Anton Mishchuk Multi language FBP with Flowex by Anton Mishchuk
Multi language FBP with Flowex by Anton Mishchuk
 
Detective story of one clever user - Lightning Talk By Sergiy Kukunin
Detective story of one clever user - Lightning Talk By Sergiy KukuninDetective story of one clever user - Lightning Talk By Sergiy Kukunin
Detective story of one clever user - Lightning Talk By Sergiy Kukunin
 
CryptoParty: Introduction by Olexii Markovets
CryptoParty: Introduction by Olexii MarkovetsCryptoParty: Introduction by Olexii Markovets
CryptoParty: Introduction by Olexii Markovets
 
How to make first million by 30 (or not, but tryin') - by Marek Piasecki
How to make first million by 30 (or not, but tryin') - by Marek PiaseckiHow to make first million by 30 (or not, but tryin') - by Marek Piasecki
How to make first million by 30 (or not, but tryin') - by Marek Piasecki
 
GIS on Rails by Oleksandr Kychun
GIS on Rails by Oleksandr Kychun GIS on Rails by Oleksandr Kychun
GIS on Rails by Oleksandr Kychun
 
Unikernels - Keep It Simple to the Bare Metal
Unikernels - Keep It Simple to the Bare MetalUnikernels - Keep It Simple to the Bare Metal
Unikernels - Keep It Simple to the Bare Metal
 
HTML Canvas tips & tricks - Lightning Talk by Roman Rodych
 HTML Canvas tips & tricks - Lightning Talk by Roman Rodych HTML Canvas tips & tricks - Lightning Talk by Roman Rodych
HTML Canvas tips & tricks - Lightning Talk by Roman Rodych
 

Recently uploaded

Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineeringssuserb3a23b
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 

Recently uploaded (20)

Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineering
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 

Ramda lets write declarative js

  • 1. Ramda let's write declarative js Roman Rodych Innocode
  • 2. What this talk about? Approaches
  • 4. What we want? ● Describe what to do instead of how ● Avoid duplication ● Stop reinventing common functionality ● Composition ● Less code - less bugs))
  • 6. Accept functions as arguments [1, 2, 3].map(function (x) { return -x }) Return function as result function fn (a, b) { return a + b }.bind(undefined, 1, 2) // => fn(1, 2) Higher order functions
  • 7. Currying var add = R.curry(function (x, y) { return x + y }) add(4, 2) // 6 add(4)(2) // 6 var add4 = add(4) // fn ! add4(2) // 6 add() // fn !
  • 8. Function first, data last var data = [ {id: 1, price: “33.00”, amount: 798}, {id: 5, price: “22.00”, amount: 0}, … ] // Our task is to get all sold products var getProducts = R.filter( R.propEq(“amount”, 0) ) // (list) => list.filter( (item) => item.amount === 0 ) getProducts(data) // [{id: 5, price: “22.00”, amount: 0}, ...]
  • 9. Dictionary for the next slide R.pipe - Performs left-to-right function composition. The leftmost function may have any arity; the remaining functions must be unary. R.prop - Returns a function that when supplied an object returns the indicated property of that object, if it exists. R.__ - A special placeholder value used to specify "gaps" within curried functions, allowing partial application of any combination of arguments, regardless of their positions. R.gt - (a, b) => a > b
  • 10. Functions composition e.g.: pipe, compose... var data = [ {id: 1, price: “150.00”, amount: 798}, {id: 5, price: “22.00”, amount: 0}, … ] // Now task is to get “id” and “price” of all available and expansive products var available = R.pipe(R.prop(“amount”), R.gt(R.__, 0)) // (item) => item.amount > 0 var expansive = R.pipe(R.prop(“price”), parseFloat, R.gt(R.__, 100)) // (item) => parseFloat(item.price) > 100 ...
  • 11. Functions composition II var data = [ {id: 1, price: “150.00”, amount: 798}, {id: 5, price: “22.00”, amount: 0}, … ] ... var filterProducts = R.filter( R.allPass([available, expansive])) var getProducts = R.pipe( filterProducts, R.pick([“id”, “price”]) ) getProducts(data) // [{id: 1, price: “150.00”, amount: 798}, ...]
  • 12. Point free - function evolution Past (dark ages) function makeMeHappy() { b = a + 42 // a and b are somewhere in the scope } Present (renaissance) const makeMeHappy = a => a + 42 Future (post-postmodernism but nobody knows, really...) const makeMeHappy = R.add(42)
  • 13. Dictionary for next slide R.converge - Boring long definition… R.find - Returns the first element of the list which matches the predicate R.nthArg - Returns a function which returns its nth argument
  • 14. Point free II “overrefactoring” var numberPropGt = R.curryN(3, R. converge( R.gt, [ R.pipe( R.converge(R.prop, [R.nthArg(0), R.nthArg(2) ]), parseFloat ), R.nthArg(1) ] )) var available = numberPropGt(“amount”, 0) // (item) => parseFloat(item.amount) > 0 var expansive = numberPropGt(“price”, 100) // (item) => parseFloat(item.price) > 100 ...
  • 15.
  • 16. Point free III real example // findById :: String -> Array -> Object const findById = R.converge( R.find, [ R.pipe(R.nthArg(0), R.propEq("id")), R.nthArg(1) ] )
  • 17. Price $$$ ● easy ● fast ● lightNot so
  • 19. When to use ● DSLs ● Rich business logic handlers ● Your option...
  • 20. Useful info ● ramdajs.com ● github.com/MostlyAdequate/mostly-adequate-guide ● youtube.com/channel/UCKjVLbSDoM-8-eEM7A30igA ● youtube.com/watch?v=m3svKOdZijA ● sitepoint.com/functional-programming-techniques-with-ruby-part-i ● github.com/solnic/transproc
  • 22. You can try ● purescript.org ● fitzgen.github.io/wu.js ● lodash.com