ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Functional Programming
A brief, yet practical introduction
What is functional programming?
¡ñ Immutable data, first class functions, currying, mapping, reducing,
pipelining, recursing¡­
Software composed of pure functions
¡°
¡±
Pure Functions
¡ï A pure function is a function that has no side effects
The function doesn¡¯t rely on data outside the current function, and it
doesn¡¯t change data that exists outside of the current function
¡ï Given the same inputs, it will always return the same output
¡°
¡±
DO everything with functions
Avoid side effects
var potato = 0;
function increment() {
return potato += 1;
}
increment(potato) {
return potato + 1;
}
non-functional
functional
Declarative not imperative
function sumOfSquares(nums) {
var i, sum = 0, squares = [];
for (i = 0; i < nums.length; i++) {
squares.push(nums[i]*nums[i]);
}
for (i = 0; i < squares.length; i++) {
sum += squares[i];
}
return sum;
}
console.log(sumOfSquares([1, 2, 3, 4, 5]));
Imperative
¡ï Not how, but what to do
Declarative not imperative
function sumOfSquares2(nums) {
return nums
.map(function(num) { return num * num; })
.reduce(function(start, num) { return start + num; }, 0)
;
}
console.log(sumOfSquares([1, 2, 3, 4, 5]));
Declarative
Higher Order functions
¡ï A function that takes a function as an input or returns a function as output,
or both
function speakTruth(name) {
return function (string) {
return name + ¡° ¡± + string;
};
}
var truthifier = speakTruth(¡°Ed¡±);
truthifier(¡°is bad at foos¡±);
=> ¡°Ed is bad at foos¡±
Don¡¯t iterate
¡ï Use map and reduce
A Map takes a function and a collection of items. It
makes a new, empty collection, runs the function on each
item in the original collection, and inserts each return
value into the new collection. It then returns the new
collection.
Map
Reduce takes a function and a collection of
items. It returns a value that is created by
combining the items.
Reduce
Map, an eggjampool
var names = [¡°Mary¡±, ¡°Isla¡±, ¡°Sam¡±];
var code_names = [¡°Mr. Pink¡±, ¡°Mr. Orange¡±, ¡°Mr. Blonde¡±];
for(var i in code_names) {
var randomIndex = Math.floor(Math.random() * code_names.length);
var randomValue = code_names[randomIndex];
names[i] = randomValue;
}
console.log(names);
=> ["Mr. Blonde", "Mr. Pink", "Mr. Pink"]
Iterative Approach
Map, an eggjampool cont.
var names = [¡°Mary¡±, ¡°Isla¡±, ¡°Sam¡±];
var code_names = [¡°Mr. Pink¡±, ¡°Mr. Orange¡±, ¡°Mr. Blonde¡±];
names = names.map(function(item) {
var randomIndex = Math.floor(Math.random() * code_names.length);
var randomValue = code_names[randomIndex];
return randomValue;
});
console.log(names);
=> ["Mr. Orange", "Mr. Orange", "Mr. Blonde"]
Using Map
Pure Functions, an example
¡ï A pure function is a function that has no side effects
var a = 0;
function increment() {
return a += 1;
}
increment(a) {
return a + 1;
}
non-functional
functional
The end

More Related Content

What's hot (17)

MS Sql Server: Doing Calculations With Functions
MS Sql Server: Doing Calculations With FunctionsMS Sql Server: Doing Calculations With Functions
MS Sql Server: Doing Calculations With Functions
DataminingTools Inc
?
16858 memory management2
16858 memory management216858 memory management2
16858 memory management2
Aanand Singh
?
Uts
UtsUts
Uts
pencari buku
?
Curry functions in Javascript
Curry functions in JavascriptCurry functions in Javascript
Curry functions in Javascript
Anand Kumar
?
random forest regression
random forest regressionrandom forest regression
random forest regression
Akhilesh Joshi
?
Why Haskell Matters
Why Haskell MattersWhy Haskell Matters
Why Haskell Matters
romanandreg
?
Statistics - ArgMax Equation
Statistics - ArgMax EquationStatistics - ArgMax Equation
Statistics - ArgMax Equation
Andrew Ferlitsch
?
Programming the cloud with Skywriting
Programming the cloud with SkywritingProgramming the cloud with Skywriting
Programming the cloud with Skywriting
Derek Murray
?
Lessons learned from functional programming
Lessons learned from functional programmingLessons learned from functional programming
Lessons learned from functional programming
BryceLohr
?
Add Some Fun to Your Functional Programming With RXJS
Add Some Fun to Your Functional Programming With RXJSAdd Some Fun to Your Functional Programming With RXJS
Add Some Fun to Your Functional Programming With RXJS
Ryan Anklam
?
(Almost) Serverless Analytics System with BigQuery & AppEngine
(Almost) Serverless Analytics System with BigQuery & AppEngine(Almost) Serverless Analytics System with BigQuery & AppEngine
(Almost) Serverless Analytics System with BigQuery & AppEngine
Gabriel PREDA
?
Queue oop
Queue   oopQueue   oop
Queue oop
Gouda Mando
?
2 18-2018-all teams total runs
2 18-2018-all teams total runs2 18-2018-all teams total runs
2 18-2018-all teams total runs
Alexander Bitar
?
Use of django at jolt online v3
Use of django at jolt online v3Use of django at jolt online v3
Use of django at jolt online v3
Jaime Buelta
?
20160616¼¼Êõ»áÒé
20160616¼¼Êõ»áÒé20160616¼¼Êõ»áÒé
20160616¼¼Êõ»áÒé
Jason Kuan
?
Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked List
PTCL
?
Mi primer map reduce
Mi primer map reduceMi primer map reduce
Mi primer map reduce
Ruben Orta
?
MS Sql Server: Doing Calculations With Functions
MS Sql Server: Doing Calculations With FunctionsMS Sql Server: Doing Calculations With Functions
MS Sql Server: Doing Calculations With Functions
DataminingTools Inc
?
16858 memory management2
16858 memory management216858 memory management2
16858 memory management2
Aanand Singh
?
Curry functions in Javascript
Curry functions in JavascriptCurry functions in Javascript
Curry functions in Javascript
Anand Kumar
?
Why Haskell Matters
Why Haskell MattersWhy Haskell Matters
Why Haskell Matters
romanandreg
?
Programming the cloud with Skywriting
Programming the cloud with SkywritingProgramming the cloud with Skywriting
Programming the cloud with Skywriting
Derek Murray
?
Lessons learned from functional programming
Lessons learned from functional programmingLessons learned from functional programming
Lessons learned from functional programming
BryceLohr
?
Add Some Fun to Your Functional Programming With RXJS
Add Some Fun to Your Functional Programming With RXJSAdd Some Fun to Your Functional Programming With RXJS
Add Some Fun to Your Functional Programming With RXJS
Ryan Anklam
?
(Almost) Serverless Analytics System with BigQuery & AppEngine
(Almost) Serverless Analytics System with BigQuery & AppEngine(Almost) Serverless Analytics System with BigQuery & AppEngine
(Almost) Serverless Analytics System with BigQuery & AppEngine
Gabriel PREDA
?
2 18-2018-all teams total runs
2 18-2018-all teams total runs2 18-2018-all teams total runs
2 18-2018-all teams total runs
Alexander Bitar
?
Use of django at jolt online v3
Use of django at jolt online v3Use of django at jolt online v3
Use of django at jolt online v3
Jaime Buelta
?
20160616¼¼Êõ»áÒé
20160616¼¼Êõ»áÒé20160616¼¼Êõ»áÒé
20160616¼¼Êõ»áÒé
Jason Kuan
?
Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked List
PTCL
?
Mi primer map reduce
Mi primer map reduceMi primer map reduce
Mi primer map reduce
Ruben Orta
?

Similar to Functional programming (20)

Short intro to ECMAScript
Short intro to ECMAScriptShort intro to ECMAScript
Short intro to ECMAScript
Jussi Pohjolainen
?
Thinking in Functions: Functional Programming in Python
Thinking in Functions: Functional Programming in PythonThinking in Functions: Functional Programming in Python
Thinking in Functions: Functional Programming in Python
Anoop Thomas Mathew
?
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
Arturo Herrero
?
Composition in JavaScript
Composition in JavaScriptComposition in JavaScript
Composition in JavaScript
Josh Mock
?
cs3381-object oriented programming-ab-manual
cs3381-object oriented programming-ab-manualcs3381-object oriented programming-ab-manual
cs3381-object oriented programming-ab-manual
karthikeyan411470
?
Fp
FpFp
Fp
Naveenkumar Muguda
?
Functional programming basics
Functional programming basicsFunctional programming basics
Functional programming basics
openbala
?
Functional Programming for OO Programmers (part 2)
Functional Programming for OO Programmers (part 2)Functional Programming for OO Programmers (part 2)
Functional Programming for OO Programmers (part 2)
Calvin Cheng
?
01 Introduction to Kotlin - Programming in Kotlin.pptx
01 Introduction to Kotlin - Programming in Kotlin.pptx01 Introduction to Kotlin - Programming in Kotlin.pptx
01 Introduction to Kotlin - Programming in Kotlin.pptx
IvanZawPhyo
?
Introduction to Kotlin.pptx
Introduction to Kotlin.pptxIntroduction to Kotlin.pptx
Introduction to Kotlin.pptx
AzharFauzan9
?
Learning Functional Programming Without Growing a Neckbeard
Learning Functional Programming Without Growing a NeckbeardLearning Functional Programming Without Growing a Neckbeard
Learning Functional Programming Without Growing a Neckbeard
Kelsey Gilmore-Innis
?
8558537werr.pptx
8558537werr.pptx8558537werr.pptx
8558537werr.pptx
ssuser8a9aac
?
25-functions.ppt
25-functions.ppt25-functions.ppt
25-functions.ppt
JyothiAmpally
?
Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)
Scott Wlaschin
?
Functional Programming in Swift
Functional Programming in SwiftFunctional Programming in Swift
Functional Programming in Swift
Saugat Gautam
?
Five Languages in a Moment
Five Languages in a MomentFive Languages in a Moment
Five Languages in a Moment
Sergio Gil
?
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchained
Eduard Tom¨¤s
?
Something about Golang
Something about GolangSomething about Golang
Something about Golang
Anton Arhipov
?
81818088 isc-class-xii-computer-science-project-java-programs
81818088 isc-class-xii-computer-science-project-java-programs81818088 isc-class-xii-computer-science-project-java-programs
81818088 isc-class-xii-computer-science-project-java-programs
Abhishek Jena
?
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScript
niklal
?
Thinking in Functions: Functional Programming in Python
Thinking in Functions: Functional Programming in PythonThinking in Functions: Functional Programming in Python
Thinking in Functions: Functional Programming in Python
Anoop Thomas Mathew
?
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
Arturo Herrero
?
Composition in JavaScript
Composition in JavaScriptComposition in JavaScript
Composition in JavaScript
Josh Mock
?
cs3381-object oriented programming-ab-manual
cs3381-object oriented programming-ab-manualcs3381-object oriented programming-ab-manual
cs3381-object oriented programming-ab-manual
karthikeyan411470
?
Functional programming basics
Functional programming basicsFunctional programming basics
Functional programming basics
openbala
?
Functional Programming for OO Programmers (part 2)
Functional Programming for OO Programmers (part 2)Functional Programming for OO Programmers (part 2)
Functional Programming for OO Programmers (part 2)
Calvin Cheng
?
01 Introduction to Kotlin - Programming in Kotlin.pptx
01 Introduction to Kotlin - Programming in Kotlin.pptx01 Introduction to Kotlin - Programming in Kotlin.pptx
01 Introduction to Kotlin - Programming in Kotlin.pptx
IvanZawPhyo
?
Introduction to Kotlin.pptx
Introduction to Kotlin.pptxIntroduction to Kotlin.pptx
Introduction to Kotlin.pptx
AzharFauzan9
?
Learning Functional Programming Without Growing a Neckbeard
Learning Functional Programming Without Growing a NeckbeardLearning Functional Programming Without Growing a Neckbeard
Learning Functional Programming Without Growing a Neckbeard
Kelsey Gilmore-Innis
?
Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)
Scott Wlaschin
?
Functional Programming in Swift
Functional Programming in SwiftFunctional Programming in Swift
Functional Programming in Swift
Saugat Gautam
?
Five Languages in a Moment
Five Languages in a MomentFive Languages in a Moment
Five Languages in a Moment
Sergio Gil
?
81818088 isc-class-xii-computer-science-project-java-programs
81818088 isc-class-xii-computer-science-project-java-programs81818088 isc-class-xii-computer-science-project-java-programs
81818088 isc-class-xii-computer-science-project-java-programs
Abhishek Jena
?
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScript
niklal
?

Recently uploaded (20)

wAIred_VoxxedDaysAmsterdam_03042025.pptx
wAIred_VoxxedDaysAmsterdam_03042025.pptxwAIred_VoxxedDaysAmsterdam_03042025.pptx
wAIred_VoxxedDaysAmsterdam_03042025.pptx
SimonedeGijt
?
ESET NOD32 Antivirus Crack with License Key 2025
ESET NOD32 Antivirus Crack with License Key 2025ESET NOD32 Antivirus Crack with License Key 2025
ESET NOD32 Antivirus Crack with License Key 2025
umeerbinfaizan
?
ESET Smart Security Crack + Activation Key 2025 [Latest]
ESET Smart Security Crack + Activation Key 2025 [Latest]ESET Smart Security Crack + Activation Key 2025 [Latest]
ESET Smart Security Crack + Activation Key 2025 [Latest]
umeerbinfaizan
?
The Missing Voices: Unearthing the Impact of Survivorship Bias on Women in Te...
The Missing Voices: Unearthing the Impact of Survivorship Bias on Women in Te...The Missing Voices: Unearthing the Impact of Survivorship Bias on Women in Te...
The Missing Voices: Unearthing the Impact of Survivorship Bias on Women in Te...
Imma Valls Bernaus
?
Wondershare PDFelement Pro Crack FREE Download
Wondershare PDFelement Pro Crack FREE DownloadWondershare PDFelement Pro Crack FREE Download
Wondershare PDFelement Pro Crack FREE Download
waqarcracker5
?
mORMot 2 - Pascal Cafe 2025 in Nederlands
mORMot 2 - Pascal Cafe 2025 in NederlandsmORMot 2 - Pascal Cafe 2025 in Nederlands
mORMot 2 - Pascal Cafe 2025 in Nederlands
Arnaud Bouchez
?
Wilcom Embroidery Studio E Crack 2025 FREE
Wilcom Embroidery Studio E Crack 2025 FREEWilcom Embroidery Studio E Crack 2025 FREE
Wilcom Embroidery Studio E Crack 2025 FREE
muhammadwaqaryounus6
?
[Roundtable] Choreo - The AI-Native Internal Developer Platform as a Service
[Roundtable] Choreo - The AI-Native Internal Developer Platform as a Service[Roundtable] Choreo - The AI-Native Internal Developer Platform as a Service
[Roundtable] Choreo - The AI-Native Internal Developer Platform as a Service
WSO2
?
Microsoft Office Crack + Product key Download Free Version 2025
Microsoft Office Crack + Product key Download Free Version 2025Microsoft Office Crack + Product key Download Free Version 2025
Microsoft Office Crack + Product key Download Free Version 2025
hamza752796
?
Migrating GitHub Actions with Nested Virtualization to Cloud Native Ecosystem...
Migrating GitHub Actions with Nested Virtualization to Cloud Native Ecosystem...Migrating GitHub Actions with Nested Virtualization to Cloud Native Ecosystem...
Migrating GitHub Actions with Nested Virtualization to Cloud Native Ecosystem...
KCD Guadalajara
?
Marketo Engage North America Virtual User Group: Adobe Summit 2025 recap
Marketo Engage North America Virtual User Group: Adobe Summit 2025 recapMarketo Engage North America Virtual User Group: Adobe Summit 2025 recap
Marketo Engage North America Virtual User Group: Adobe Summit 2025 recap
BradBedford3
?
Coreldraw 2021 Crack Latest Version 2025
Coreldraw 2021 Crack Latest Version 2025Coreldraw 2021 Crack Latest Version 2025
Coreldraw 2021 Crack Latest Version 2025
blouch31kp
?
Internet Download Manager (IDM) Crack + Lisence key Latest version 2025
Internet Download Manager (IDM) Crack + Lisence key Latest version 2025Internet Download Manager (IDM) Crack + Lisence key Latest version 2025
Internet Download Manager (IDM) Crack + Lisence key Latest version 2025
shahzad011kp
?
AOMEI Backupper Crack 2025 FREE Download
AOMEI Backupper Crack 2025 FREE DownloadAOMEI Backupper Crack 2025 FREE Download
AOMEI Backupper Crack 2025 FREE Download
muhammadwaqaryounus6
?
Sublime Text Crack 2025 LATEST Version FREE
Sublime Text Crack  2025 LATEST Version FREESublime Text Crack  2025 LATEST Version FREE
Sublime Text Crack 2025 LATEST Version FREE
muhammadwaqaryounus6
?
PDF Reader Pro Crack FREE Download Latest Version
PDF Reader Pro Crack FREE Download Latest VersionPDF Reader Pro Crack FREE Download Latest Version
PDF Reader Pro Crack FREE Download Latest Version
waqarcracker5
?
Windows 8.1 Pro Activator Crack Version [April-2025]
Windows 8.1 Pro Activator Crack Version [April-2025]Windows 8.1 Pro Activator Crack Version [April-2025]
Windows 8.1 Pro Activator Crack Version [April-2025]
jhonjosh91
?
Hands-On AWS: Java SDK + CLI for Cloud Developers
Hands-On AWS: Java SDK + CLI for Cloud DevelopersHands-On AWS: Java SDK + CLI for Cloud Developers
Hands-On AWS: Java SDK + CLI for Cloud Developers
Meetu Maltiar
?
Driver Genius 24 Crack 2025 License Key Free Download
Driver Genius 24 Crack 2025 License Key Free DownloadDriver Genius 24 Crack 2025 License Key Free Download
Driver Genius 24 Crack 2025 License Key Free Download
umeerbinfaizan
?
IObit Driver Booster Pro Serial Key v11.2.0.46 Full Crack 2025
IObit Driver Booster Pro Serial Key v11.2.0.46 Full Crack 2025IObit Driver Booster Pro Serial Key v11.2.0.46 Full Crack 2025
IObit Driver Booster Pro Serial Key v11.2.0.46 Full Crack 2025
alibajava70
?
wAIred_VoxxedDaysAmsterdam_03042025.pptx
wAIred_VoxxedDaysAmsterdam_03042025.pptxwAIred_VoxxedDaysAmsterdam_03042025.pptx
wAIred_VoxxedDaysAmsterdam_03042025.pptx
SimonedeGijt
?
ESET NOD32 Antivirus Crack with License Key 2025
ESET NOD32 Antivirus Crack with License Key 2025ESET NOD32 Antivirus Crack with License Key 2025
ESET NOD32 Antivirus Crack with License Key 2025
umeerbinfaizan
?
ESET Smart Security Crack + Activation Key 2025 [Latest]
ESET Smart Security Crack + Activation Key 2025 [Latest]ESET Smart Security Crack + Activation Key 2025 [Latest]
ESET Smart Security Crack + Activation Key 2025 [Latest]
umeerbinfaizan
?
The Missing Voices: Unearthing the Impact of Survivorship Bias on Women in Te...
The Missing Voices: Unearthing the Impact of Survivorship Bias on Women in Te...The Missing Voices: Unearthing the Impact of Survivorship Bias on Women in Te...
The Missing Voices: Unearthing the Impact of Survivorship Bias on Women in Te...
Imma Valls Bernaus
?
Wondershare PDFelement Pro Crack FREE Download
Wondershare PDFelement Pro Crack FREE DownloadWondershare PDFelement Pro Crack FREE Download
Wondershare PDFelement Pro Crack FREE Download
waqarcracker5
?
mORMot 2 - Pascal Cafe 2025 in Nederlands
mORMot 2 - Pascal Cafe 2025 in NederlandsmORMot 2 - Pascal Cafe 2025 in Nederlands
mORMot 2 - Pascal Cafe 2025 in Nederlands
Arnaud Bouchez
?
Wilcom Embroidery Studio E Crack 2025 FREE
Wilcom Embroidery Studio E Crack 2025 FREEWilcom Embroidery Studio E Crack 2025 FREE
Wilcom Embroidery Studio E Crack 2025 FREE
muhammadwaqaryounus6
?
[Roundtable] Choreo - The AI-Native Internal Developer Platform as a Service
[Roundtable] Choreo - The AI-Native Internal Developer Platform as a Service[Roundtable] Choreo - The AI-Native Internal Developer Platform as a Service
[Roundtable] Choreo - The AI-Native Internal Developer Platform as a Service
WSO2
?
Microsoft Office Crack + Product key Download Free Version 2025
Microsoft Office Crack + Product key Download Free Version 2025Microsoft Office Crack + Product key Download Free Version 2025
Microsoft Office Crack + Product key Download Free Version 2025
hamza752796
?
Migrating GitHub Actions with Nested Virtualization to Cloud Native Ecosystem...
Migrating GitHub Actions with Nested Virtualization to Cloud Native Ecosystem...Migrating GitHub Actions with Nested Virtualization to Cloud Native Ecosystem...
Migrating GitHub Actions with Nested Virtualization to Cloud Native Ecosystem...
KCD Guadalajara
?
Marketo Engage North America Virtual User Group: Adobe Summit 2025 recap
Marketo Engage North America Virtual User Group: Adobe Summit 2025 recapMarketo Engage North America Virtual User Group: Adobe Summit 2025 recap
Marketo Engage North America Virtual User Group: Adobe Summit 2025 recap
BradBedford3
?
Coreldraw 2021 Crack Latest Version 2025
Coreldraw 2021 Crack Latest Version 2025Coreldraw 2021 Crack Latest Version 2025
Coreldraw 2021 Crack Latest Version 2025
blouch31kp
?
Internet Download Manager (IDM) Crack + Lisence key Latest version 2025
Internet Download Manager (IDM) Crack + Lisence key Latest version 2025Internet Download Manager (IDM) Crack + Lisence key Latest version 2025
Internet Download Manager (IDM) Crack + Lisence key Latest version 2025
shahzad011kp
?
AOMEI Backupper Crack 2025 FREE Download
AOMEI Backupper Crack 2025 FREE DownloadAOMEI Backupper Crack 2025 FREE Download
AOMEI Backupper Crack 2025 FREE Download
muhammadwaqaryounus6
?
Sublime Text Crack 2025 LATEST Version FREE
Sublime Text Crack  2025 LATEST Version FREESublime Text Crack  2025 LATEST Version FREE
Sublime Text Crack 2025 LATEST Version FREE
muhammadwaqaryounus6
?
PDF Reader Pro Crack FREE Download Latest Version
PDF Reader Pro Crack FREE Download Latest VersionPDF Reader Pro Crack FREE Download Latest Version
PDF Reader Pro Crack FREE Download Latest Version
waqarcracker5
?
Windows 8.1 Pro Activator Crack Version [April-2025]
Windows 8.1 Pro Activator Crack Version [April-2025]Windows 8.1 Pro Activator Crack Version [April-2025]
Windows 8.1 Pro Activator Crack Version [April-2025]
jhonjosh91
?
Hands-On AWS: Java SDK + CLI for Cloud Developers
Hands-On AWS: Java SDK + CLI for Cloud DevelopersHands-On AWS: Java SDK + CLI for Cloud Developers
Hands-On AWS: Java SDK + CLI for Cloud Developers
Meetu Maltiar
?
Driver Genius 24 Crack 2025 License Key Free Download
Driver Genius 24 Crack 2025 License Key Free DownloadDriver Genius 24 Crack 2025 License Key Free Download
Driver Genius 24 Crack 2025 License Key Free Download
umeerbinfaizan
?
IObit Driver Booster Pro Serial Key v11.2.0.46 Full Crack 2025
IObit Driver Booster Pro Serial Key v11.2.0.46 Full Crack 2025IObit Driver Booster Pro Serial Key v11.2.0.46 Full Crack 2025
IObit Driver Booster Pro Serial Key v11.2.0.46 Full Crack 2025
alibajava70
?

Functional programming

  • 1. Functional Programming A brief, yet practical introduction
  • 2. What is functional programming? ¡ñ Immutable data, first class functions, currying, mapping, reducing, pipelining, recursing¡­ Software composed of pure functions ¡° ¡±
  • 3. Pure Functions ¡ï A pure function is a function that has no side effects The function doesn¡¯t rely on data outside the current function, and it doesn¡¯t change data that exists outside of the current function ¡ï Given the same inputs, it will always return the same output ¡° ¡±
  • 4. DO everything with functions
  • 5. Avoid side effects var potato = 0; function increment() { return potato += 1; } increment(potato) { return potato + 1; } non-functional functional
  • 6. Declarative not imperative function sumOfSquares(nums) { var i, sum = 0, squares = []; for (i = 0; i < nums.length; i++) { squares.push(nums[i]*nums[i]); } for (i = 0; i < squares.length; i++) { sum += squares[i]; } return sum; } console.log(sumOfSquares([1, 2, 3, 4, 5])); Imperative ¡ï Not how, but what to do
  • 7. Declarative not imperative function sumOfSquares2(nums) { return nums .map(function(num) { return num * num; }) .reduce(function(start, num) { return start + num; }, 0) ; } console.log(sumOfSquares([1, 2, 3, 4, 5])); Declarative
  • 8. Higher Order functions ¡ï A function that takes a function as an input or returns a function as output, or both function speakTruth(name) { return function (string) { return name + ¡° ¡± + string; }; } var truthifier = speakTruth(¡°Ed¡±); truthifier(¡°is bad at foos¡±); => ¡°Ed is bad at foos¡±
  • 9. Don¡¯t iterate ¡ï Use map and reduce A Map takes a function and a collection of items. It makes a new, empty collection, runs the function on each item in the original collection, and inserts each return value into the new collection. It then returns the new collection. Map Reduce takes a function and a collection of items. It returns a value that is created by combining the items. Reduce
  • 10. Map, an eggjampool var names = [¡°Mary¡±, ¡°Isla¡±, ¡°Sam¡±]; var code_names = [¡°Mr. Pink¡±, ¡°Mr. Orange¡±, ¡°Mr. Blonde¡±]; for(var i in code_names) { var randomIndex = Math.floor(Math.random() * code_names.length); var randomValue = code_names[randomIndex]; names[i] = randomValue; } console.log(names); => ["Mr. Blonde", "Mr. Pink", "Mr. Pink"] Iterative Approach
  • 11. Map, an eggjampool cont. var names = [¡°Mary¡±, ¡°Isla¡±, ¡°Sam¡±]; var code_names = [¡°Mr. Pink¡±, ¡°Mr. Orange¡±, ¡°Mr. Blonde¡±]; names = names.map(function(item) { var randomIndex = Math.floor(Math.random() * code_names.length); var randomValue = code_names[randomIndex]; return randomValue; }); console.log(names); => ["Mr. Orange", "Mr. Orange", "Mr. Blonde"] Using Map
  • 12. Pure Functions, an example ¡ï A pure function is a function that has no side effects var a = 0; function increment() { return a += 1; } increment(a) { return a + 1; } non-functional functional