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

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 

Dernier (20)

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 

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