SlideShare une entreprise Scribd logo
1  sur  15
{

Functional programming in JavaScript
… and the curious case of _.js

Om Shankar
JavaScripter @ InMobi

bit.ly/omshankar
Functional programming is the use of functions that
transform values into units of abstraction, subsequently
used to build software systems.
Do Something !
– by doing this, and then that,
– and don’t forget to do this at the end of all that.

Get Something Done !
– I don’t care how you do it,
– also, when I want it done again, it should be as easy as it was the first
time.

Declarative programming: stackoverflow.com/a/8357604/1249219
Closures

Flow and Chaining

Recursion

{

Functions constructing Functions

The building blocks of Functional JavaScript

Mutation policies
Functions passed as parameters
Class-less JavaScript
• Should travel in First Class
• Should be Pure, hence, should be re-usable
• Should be Applicative
- function A supplied to B should perform actions in B’s context.
Strings are first class in JS,
- so are functions with all possible operations
// Both can be stored
var string = "BangaloreJS";
var stringFn = function() { return "BangaloreJS"; }
// can be used on the fly, as an expression:
// string
"BangaloreJS";
"BangaloreJS".slice(3);
// function
"BangaloreJS" + (function(){ return " Rocks !!"; }());
A pure function
•
•
•
•

takes argument(s)
returns value(s)
returns same value(s) for same argument(s)
does nothing else !

Arguments

Return value
An impure function
• takes argument(s)
• returns value(s)
• reads/writes external states, for
eg., modifies global DOM, objects, arrays.
Read State
Arguments

Return value
tightly coupled with read state

Change State
_. map
reduce / reduceRight
find / detect / where
filter / reject
every / some
...
_.bind(scopeObject, normalFn);
_.bindAll(obj, fn1, [fn2, fn3, ...]);

• Creating a complement function
• Creating a repeater function
Functions taking functions as parameters

function repeat(times, fn) {
return _.map(_.range(times), fn);
}
Functions returning functions as value
var numData = [1,2,null,4,5];
_.reduce(numData, function(tot, curr) {
return tot * curr;
});
// Problem?
// Solution: function returning modified safe function
// and not imperatively modified data
// though what we actually do is modify data on the fly
RxJS
- Reactive extensions for JS by Microsoft

{

Declarative JavaScript Libraries

Bilby.js - bilby.brianmckenna.org
Allong.es - github.com/fogus/lemonad
CoffeScript - coffeescript.org

{

Declarative JavaScript Compilers

ClojureScript - github.com/clojure/clojurescript

ROY - bilby.brianmckenna.org
@om_invincible

{

geekyogi.com

End of Part - 1
Happy JavaScript-ing

github.com/OmShiv

bit.ly/omshankar

Contenu connexe

Tendances

JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)Piyush Katariya
 
Model with actors and implement with Akka
Model with actors and implement with AkkaModel with actors and implement with Akka
Model with actors and implement with AkkaNgoc Dao
 
Lviv MD Day 2015 Павло Захаров "Reactive cocoa: paradigm shift"
Lviv MD Day 2015 Павло Захаров "Reactive cocoa: paradigm shift"Lviv MD Day 2015 Павло Захаров "Reactive cocoa: paradigm shift"
Lviv MD Day 2015 Павло Захаров "Reactive cocoa: paradigm shift"Lviv Startup Club
 
Functional programming and ruby in functional style
Functional programming and ruby in functional styleFunctional programming and ruby in functional style
Functional programming and ruby in functional styleNiranjan Sarade
 
Qtp training session IV
Qtp training session IVQtp training session IV
Qtp training session IVAisha Mazhar
 
Continuations in scala (incomplete version)
Continuations in scala (incomplete version)Continuations in scala (incomplete version)
Continuations in scala (incomplete version)Fuqiang Wang
 
Groovy / comparison with java
Groovy / comparison with javaGroovy / comparison with java
Groovy / comparison with javaLiviu Tudor
 
libSEDML (Harmony 2012)
libSEDML (Harmony 2012)libSEDML (Harmony 2012)
libSEDML (Harmony 2012)Frank Bergmann
 
What’s new in Kotlin?
What’s new in Kotlin?What’s new in Kotlin?
What’s new in Kotlin?Squareboat
 
Scala the-good-parts
Scala the-good-partsScala the-good-parts
Scala the-good-partsFuqiang Wang
 
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
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced JavascriptDhruvin Shah
 
JavaScript
JavaScriptJavaScript
JavaScriptStrasWeb
 
Davide Cerbo - Kotlin loves React - Codemotion Milan 2018
Davide Cerbo - Kotlin loves React - Codemotion Milan 2018Davide Cerbo - Kotlin loves React - Codemotion Milan 2018
Davide Cerbo - Kotlin loves React - Codemotion Milan 2018Codemotion
 
Async queue-transaction
Async queue-transaction Async queue-transaction
Async queue-transaction Fei (James) Liu
 
Bldr: A Minimalist JSON Templating DSL
Bldr: A Minimalist JSON Templating DSLBldr: A Minimalist JSON Templating DSL
Bldr: A Minimalist JSON Templating DSLAlex Sharp
 

Tendances (20)

JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)
 
Model with actors and implement with Akka
Model with actors and implement with AkkaModel with actors and implement with Akka
Model with actors and implement with Akka
 
Lviv MD Day 2015 Павло Захаров "Reactive cocoa: paradigm shift"
Lviv MD Day 2015 Павло Захаров "Reactive cocoa: paradigm shift"Lviv MD Day 2015 Павло Захаров "Reactive cocoa: paradigm shift"
Lviv MD Day 2015 Павло Захаров "Reactive cocoa: paradigm shift"
 
Functional programming and ruby in functional style
Functional programming and ruby in functional styleFunctional programming and ruby in functional style
Functional programming and ruby in functional style
 
Qtp training session IV
Qtp training session IVQtp training session IV
Qtp training session IV
 
Continuations in scala (incomplete version)
Continuations in scala (incomplete version)Continuations in scala (incomplete version)
Continuations in scala (incomplete version)
 
Groovy / comparison with java
Groovy / comparison with javaGroovy / comparison with java
Groovy / comparison with java
 
libSEDML (Harmony 2012)
libSEDML (Harmony 2012)libSEDML (Harmony 2012)
libSEDML (Harmony 2012)
 
What’s new in Kotlin?
What’s new in Kotlin?What’s new in Kotlin?
What’s new in Kotlin?
 
Scala the-good-parts
Scala the-good-partsScala the-good-parts
Scala the-good-parts
 
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?
 
Threads
ThreadsThreads
Threads
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
oojs
oojsoojs
oojs
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Thinking Functionally
Thinking FunctionallyThinking Functionally
Thinking Functionally
 
10. Function I
10. Function I10. Function I
10. Function I
 
Davide Cerbo - Kotlin loves React - Codemotion Milan 2018
Davide Cerbo - Kotlin loves React - Codemotion Milan 2018Davide Cerbo - Kotlin loves React - Codemotion Milan 2018
Davide Cerbo - Kotlin loves React - Codemotion Milan 2018
 
Async queue-transaction
Async queue-transaction Async queue-transaction
Async queue-transaction
 
Bldr: A Minimalist JSON Templating DSL
Bldr: A Minimalist JSON Templating DSLBldr: A Minimalist JSON Templating DSL
Bldr: A Minimalist JSON Templating DSL
 

En vedette

Introduction to MHA Lighting
Introduction to MHA LightingIntroduction to MHA Lighting
Introduction to MHA Lightingadele101
 
Mha Garage Catalogue
Mha Garage CatalogueMha Garage Catalogue
Mha Garage Catalogueadele101
 
Mha Catalogue 2012
Mha Catalogue 2012Mha Catalogue 2012
Mha Catalogue 2012adele101
 
Katalog Ajija edisi 03 Juni - Juli
Katalog Ajija edisi 03 Juni - JuliKatalog Ajija edisi 03 Juni - Juli
Katalog Ajija edisi 03 Juni - JuliDonaIncim
 
Olympic Travel Update - Vauxhall One / TfL
Olympic Travel Update - Vauxhall One / TfL Olympic Travel Update - Vauxhall One / TfL
Olympic Travel Update - Vauxhall One / TfL VauxhallOne
 
Bai giang ktlt-v2010_academia.edu-libre
Bai giang ktlt-v2010_academia.edu-libreBai giang ktlt-v2010_academia.edu-libre
Bai giang ktlt-v2010_academia.edu-libreTony Khánh
 
Gatsby powerpoint
Gatsby powerpointGatsby powerpoint
Gatsby powerpointmm232h
 
Loi santé et Transparence
Loi santé et TransparenceLoi santé et Transparence
Loi santé et TransparenceMarket iT
 
Journée nationale innovation santé
Journée nationale innovation santéJournée nationale innovation santé
Journée nationale innovation santéMarket iT
 
Mardi 31 mai 2016 | Statut et missions des MSL (Medical Science Liaison) : ...
Mardi 31 mai 2016  | Statut et missions des MSL  (Medical Science Liaison) : ...Mardi 31 mai 2016  | Statut et missions des MSL  (Medical Science Liaison) : ...
Mardi 31 mai 2016 | Statut et missions des MSL (Medical Science Liaison) : ...Market iT
 
NHS England - Managing conflicts of interest
NHS England - Managing conflicts of interestNHS England - Managing conflicts of interest
NHS England - Managing conflicts of interestMarket iT
 
Les conflits d'intérêts au sein de l'AP-HP
Les conflits d'intérêts au sein de l'AP-HPLes conflits d'intérêts au sein de l'AP-HP
Les conflits d'intérêts au sein de l'AP-HPMarket iT
 
Jeudi 24 mars 2016 | Savoir exploiter les congrès en évitant le risque de qu...
Jeudi 24 mars 2016 | Savoir exploiter les congrès en évitant  le risque de qu...Jeudi 24 mars 2016 | Savoir exploiter les congrès en évitant  le risque de qu...
Jeudi 24 mars 2016 | Savoir exploiter les congrès en évitant le risque de qu...Market iT
 
Jeudi 7 avril 2016 | Transparence et collaboration avec les personnes morales...
Jeudi 7 avril 2016 | Transparence et collaboration avec les personnes morales...Jeudi 7 avril 2016 | Transparence et collaboration avec les personnes morales...
Jeudi 7 avril 2016 | Transparence et collaboration avec les personnes morales...Market iT
 
Communique de Presse AFCDP - 24 mai 2016
Communique de Presse AFCDP - 24 mai 2016Communique de Presse AFCDP - 24 mai 2016
Communique de Presse AFCDP - 24 mai 2016Market iT
 

En vedette (20)

Real Estate Investment Trusts
Real Estate Investment TrustsReal Estate Investment Trusts
Real Estate Investment Trusts
 
Presentation1
Presentation1Presentation1
Presentation1
 
Introduction to MHA Lighting
Introduction to MHA LightingIntroduction to MHA Lighting
Introduction to MHA Lighting
 
Mha Garage Catalogue
Mha Garage CatalogueMha Garage Catalogue
Mha Garage Catalogue
 
Mha Catalogue 2012
Mha Catalogue 2012Mha Catalogue 2012
Mha Catalogue 2012
 
Who am i
Who am iWho am i
Who am i
 
Pdf piel y faremas
Pdf piel y faremasPdf piel y faremas
Pdf piel y faremas
 
Katalog Ajija edisi 03 Juni - Juli
Katalog Ajija edisi 03 Juni - JuliKatalog Ajija edisi 03 Juni - Juli
Katalog Ajija edisi 03 Juni - Juli
 
Olympic Travel Update - Vauxhall One / TfL
Olympic Travel Update - Vauxhall One / TfL Olympic Travel Update - Vauxhall One / TfL
Olympic Travel Update - Vauxhall One / TfL
 
Bai giang ktlt-v2010_academia.edu-libre
Bai giang ktlt-v2010_academia.edu-libreBai giang ktlt-v2010_academia.edu-libre
Bai giang ktlt-v2010_academia.edu-libre
 
Gatsby powerpoint
Gatsby powerpointGatsby powerpoint
Gatsby powerpoint
 
Loi santé et Transparence
Loi santé et TransparenceLoi santé et Transparence
Loi santé et Transparence
 
Journée nationale innovation santé
Journée nationale innovation santéJournée nationale innovation santé
Journée nationale innovation santé
 
Mardi 31 mai 2016 | Statut et missions des MSL (Medical Science Liaison) : ...
Mardi 31 mai 2016  | Statut et missions des MSL  (Medical Science Liaison) : ...Mardi 31 mai 2016  | Statut et missions des MSL  (Medical Science Liaison) : ...
Mardi 31 mai 2016 | Statut et missions des MSL (Medical Science Liaison) : ...
 
NHS England - Managing conflicts of interest
NHS England - Managing conflicts of interestNHS England - Managing conflicts of interest
NHS England - Managing conflicts of interest
 
Les conflits d'intérêts au sein de l'AP-HP
Les conflits d'intérêts au sein de l'AP-HPLes conflits d'intérêts au sein de l'AP-HP
Les conflits d'intérêts au sein de l'AP-HP
 
Atemporal
AtemporalAtemporal
Atemporal
 
Jeudi 24 mars 2016 | Savoir exploiter les congrès en évitant le risque de qu...
Jeudi 24 mars 2016 | Savoir exploiter les congrès en évitant  le risque de qu...Jeudi 24 mars 2016 | Savoir exploiter les congrès en évitant  le risque de qu...
Jeudi 24 mars 2016 | Savoir exploiter les congrès en évitant le risque de qu...
 
Jeudi 7 avril 2016 | Transparence et collaboration avec les personnes morales...
Jeudi 7 avril 2016 | Transparence et collaboration avec les personnes morales...Jeudi 7 avril 2016 | Transparence et collaboration avec les personnes morales...
Jeudi 7 avril 2016 | Transparence et collaboration avec les personnes morales...
 
Communique de Presse AFCDP - 24 mai 2016
Communique de Presse AFCDP - 24 mai 2016Communique de Presse AFCDP - 24 mai 2016
Communique de Presse AFCDP - 24 mai 2016
 

Similaire à Functional programming in JavaScript and the curious case of _.js

JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic FunctionsWebStackAcademy
 
Functional programming in clojure
Functional programming in clojureFunctional programming in clojure
Functional programming in clojureJuan-Manuel Gimeno
 
Awesomeness of JavaScript…almost
Awesomeness of JavaScript…almostAwesomeness of JavaScript…almost
Awesomeness of JavaScript…almostQuinton Sheppard
 
Functional programming in javascript
Functional programming in javascriptFunctional programming in javascript
Functional programming in javascriptBoris Burdiliak
 
Intro to JavaScript - Week 2: Function
Intro to JavaScript - Week 2: FunctionIntro to JavaScript - Week 2: Function
Intro to JavaScript - Week 2: FunctionJeongbae Oh
 
JavaScript - Chapter 7 - Advanced Functions
 JavaScript - Chapter 7 - Advanced Functions JavaScript - Chapter 7 - Advanced Functions
JavaScript - Chapter 7 - Advanced FunctionsWebStackAcademy
 
(3) cpp procedural programming
(3) cpp procedural programming(3) cpp procedural programming
(3) cpp procedural programmingNico Ludwig
 
Thinking Functionally - John Stevenson - Codemotion Rome 2017
Thinking Functionally - John Stevenson - Codemotion Rome 2017Thinking Functionally - John Stevenson - Codemotion Rome 2017
Thinking Functionally - John Stevenson - Codemotion Rome 2017Codemotion
 
Thinking Functionally with Clojure
Thinking Functionally with ClojureThinking Functionally with Clojure
Thinking Functionally with ClojureJohn Stevenson
 
Java Script Promise
Java Script PromiseJava Script Promise
Java Script PromiseAlok Guha
 
JavaScript For CSharp Developer
JavaScript For CSharp DeveloperJavaScript For CSharp Developer
JavaScript For CSharp DeveloperSarvesh Kushwaha
 
predefined and user defined functions
predefined and user defined functionspredefined and user defined functions
predefined and user defined functionsSwapnil Yadav
 
Douglas Crockford: Serversideness
Douglas Crockford: ServersidenessDouglas Crockford: Serversideness
Douglas Crockford: ServersidenessWebExpo
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript DevelopmentJussi Pohjolainen
 

Similaire à Functional programming in JavaScript and the curious case of _.js (20)

JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
 
Functional programming in clojure
Functional programming in clojureFunctional programming in clojure
Functional programming in clojure
 
Awesomeness of JavaScript…almost
Awesomeness of JavaScript…almostAwesomeness of JavaScript…almost
Awesomeness of JavaScript…almost
 
[2015/2016] JavaScript
[2015/2016] JavaScript[2015/2016] JavaScript
[2015/2016] JavaScript
 
JavaScript for real men
JavaScript for real menJavaScript for real men
JavaScript for real men
 
JS Essence
JS EssenceJS Essence
JS Essence
 
Functional programming in javascript
Functional programming in javascriptFunctional programming in javascript
Functional programming in javascript
 
Intro to JavaScript - Week 2: Function
Intro to JavaScript - Week 2: FunctionIntro to JavaScript - Week 2: Function
Intro to JavaScript - Week 2: Function
 
JavaScript - Chapter 7 - Advanced Functions
 JavaScript - Chapter 7 - Advanced Functions JavaScript - Chapter 7 - Advanced Functions
JavaScript - Chapter 7 - Advanced Functions
 
(3) cpp procedural programming
(3) cpp procedural programming(3) cpp procedural programming
(3) cpp procedural programming
 
Thinking Functionally - John Stevenson - Codemotion Rome 2017
Thinking Functionally - John Stevenson - Codemotion Rome 2017Thinking Functionally - John Stevenson - Codemotion Rome 2017
Thinking Functionally - John Stevenson - Codemotion Rome 2017
 
Thinking Functionally with Clojure
Thinking Functionally with ClojureThinking Functionally with Clojure
Thinking Functionally with Clojure
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Java Script Promise
Java Script PromiseJava Script Promise
Java Script Promise
 
JavaScript For CSharp Developer
JavaScript For CSharp DeveloperJavaScript For CSharp Developer
JavaScript For CSharp Developer
 
ES6 metaprogramming unleashed
ES6 metaprogramming unleashedES6 metaprogramming unleashed
ES6 metaprogramming unleashed
 
Sql functions
Sql functionsSql functions
Sql functions
 
predefined and user defined functions
predefined and user defined functionspredefined and user defined functions
predefined and user defined functions
 
Douglas Crockford: Serversideness
Douglas Crockford: ServersidenessDouglas Crockford: Serversideness
Douglas Crockford: Serversideness
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
 

Dernier

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Dernier (20)

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Functional programming in JavaScript and the curious case of _.js

  • 1. { Functional programming in JavaScript … and the curious case of _.js Om Shankar JavaScripter @ InMobi bit.ly/omshankar
  • 2. Functional programming is the use of functions that transform values into units of abstraction, subsequently used to build software systems.
  • 3. Do Something ! – by doing this, and then that, – and don’t forget to do this at the end of all that. Get Something Done ! – I don’t care how you do it, – also, when I want it done again, it should be as easy as it was the first time. Declarative programming: stackoverflow.com/a/8357604/1249219
  • 4. Closures Flow and Chaining Recursion { Functions constructing Functions The building blocks of Functional JavaScript Mutation policies Functions passed as parameters Class-less JavaScript
  • 5. • Should travel in First Class • Should be Pure, hence, should be re-usable • Should be Applicative - function A supplied to B should perform actions in B’s context.
  • 6. Strings are first class in JS, - so are functions with all possible operations // Both can be stored var string = "BangaloreJS"; var stringFn = function() { return "BangaloreJS"; } // can be used on the fly, as an expression: // string "BangaloreJS"; "BangaloreJS".slice(3); // function "BangaloreJS" + (function(){ return " Rocks !!"; }());
  • 7. A pure function • • • • takes argument(s) returns value(s) returns same value(s) for same argument(s) does nothing else ! Arguments Return value
  • 8. An impure function • takes argument(s) • returns value(s) • reads/writes external states, for eg., modifies global DOM, objects, arrays. Read State Arguments Return value tightly coupled with read state Change State
  • 9. _. map reduce / reduceRight find / detect / where filter / reject every / some ...
  • 10. _.bind(scopeObject, normalFn); _.bindAll(obj, fn1, [fn2, fn3, ...]); • Creating a complement function • Creating a repeater function
  • 11. Functions taking functions as parameters function repeat(times, fn) { return _.map(_.range(times), fn); }
  • 12. Functions returning functions as value var numData = [1,2,null,4,5]; _.reduce(numData, function(tot, curr) { return tot * curr; }); // Problem? // Solution: function returning modified safe function // and not imperatively modified data // though what we actually do is modify data on the fly
  • 13. RxJS - Reactive extensions for JS by Microsoft { Declarative JavaScript Libraries Bilby.js - bilby.brianmckenna.org Allong.es - github.com/fogus/lemonad
  • 14. CoffeScript - coffeescript.org { Declarative JavaScript Compilers ClojureScript - github.com/clojure/clojurescript ROY - bilby.brianmckenna.org
  • 15. @om_invincible { geekyogi.com End of Part - 1 Happy JavaScript-ing github.com/OmShiv bit.ly/omshankar