SlideShare a Scribd company logo
1 of 30
Download to read offline
Le retour de la fonction
@loicknuchel
High-order function
Currying
Pure function
Functor
Monad
Monoid
Immutable
Récursif
Programmation générique
for loop is everywhere
function toUpperCase(list){
var ret = [];
for(var i=0; i<list.length; i++){
ret[i] = list[i].toUpperCase();
}
return ret;
}
var names = ['Finn', 'Rey', 'Poe'];
console.log(toUpperCase(names));
// ['FINN', 'REY', 'POE']
for loop is everywhere
function toUpperCase(list){
var ret = [];
for(var i=0; i<list.length; i++){
ret[i] = list[i].toUpperCase();
}
return ret;
}
var names = ['Finn', 'Rey', 'Poe'];
console.log(toUpperCase(names));
// ['FINN', 'REY', 'POE']
Boilerplate !!!
Array.prototype.map = function(callback){
var array = this;
var result = [];
for(var i=0; i<array.length; i++){
result[i] = callback(array[i]);
}
return result;
};
for loop is everywhere
(High-order function)
for loop is everywhere
function toUpperCase(list){
return list.map(function(item){
return item.toUpperCase();
});
}
for loop is everywhere
function toUpperCase(list){
return list.map(item => item.toUpperCase());
}
Séparation technique vs métier
Array.prototype.map = function(callback){
var array = this;
var result = [];
for(var i=0; i<array.length; i++){
result[i] = callback(array[i]);
}
return result;
};
list.map(item => item.toUpperCase());
Générique / Réutilisable
Haut niveau d’abstraction
Concis / Expressif
Focalisé sur le domaine
Scala collection API (en partie)
def map[B](f: (A) => B): List[B]
def filter(p: (A) => Boolean): List[A]
def partition(p: (A) => Boolean): (List[A], List[A])
def zip[B](that: List[B]): List[(A, B)]
def sliding(size: Int): Iterator[List[A]]
def find(p: (A) => Boolean): Option[A]
def exists(p: (A) => Boolean): Boolean
def flatten[B]: List[B]
def flatMap[B](f: (A) => List[B]): List[B]
def groupBy[K](f: (A) => K): Map[K, List[A]]
def grouped(size: Int): Iterator[List[A]]
def fold[A1 >: A](z: A1)(op: (A1, A1) => A1): A1
def reduce[A1 >: A](op: (A1, A1) => A1): A1
def forall(p: (A) => Boolean): Boolean
def take(n: Int): List[A]
def drop(n: Int): List[A]
def distinct: List[A]
The billion dollar mistake !
function toUpperCase(list){
var ret = [];
for(var i=0; i<list.length; i++){
ret[i] = list[i].toUpperCase();
}
return ret;
}
Safe ?
The billion dollar mistake !
function toUpperCase(list){
var ret = [];
for(var i=0; i<list.length; i++){
ret[i] = list[i].toUpperCase();
}
return ret;
}
Unsafe !
Cannot read property 'xxx'
of undefined !!!
The billion dollar mistake !
function toUpperCase(list){
var ret = [];
for(var i=0; i<list.length; i++){
ret[i] = list[i].toUpperCase();
}
return ret;
}
function toUpperCase(list){
var ret = [];
if(Array.isArray(list)) {
for(var i=0; i<list.length; i++){
if(typeof list[i] === 'string'){
ret[i] = list[i].toUpperCase();
} else {
ret[i] = list[i];
}
}
}
return ret;
}
Unsafe ! Unreadable !
The billion dollar mistake !
function toUpperCase(list){
var ret = [];
for(var i=0; i<list.length; i++){
ret[i] = list[i].toUpperCase();
}
return ret;
}
function toUpperCase(list){
var ret = [];
if(Array.isArray(list)) {
for(var i=0; i<list.length; i++){
ret[i] = list[i].toUpperCase();
}
}
return ret;
}
function toUpperCase(list){
var ret = [];
if(Array.isArray(list)) {
for(var i=0; i<list.length; i++){
if(typeof list[i] === 'string'){
ret[i] = list[i].toUpperCase();
} else {
ret[i] = list[i];
}
}
}
return ret;
}
Unsafe ! Unreadable ! (not so) smart
The billion dollar mistake !
// no null !
def toUpperCase(list: List[String]) = list.map(_.toUpperCase)
def toUpperCase(list: List[Option[String]]) = list.map(_.map(_.toUpperCase))
List.map() vs Option.map() ???
List.map() vs Option.map() ???
Fonctors !!!
def toWords(sentences: List[String]): List[List[[String]] =
sentences.map(_.split(" ").toList)
def toWords(sentences: List[String]): List[String] =
sentences.flatMap(_.split(" ").toList)
def toWords(sentences: List[String]): List[List[[String]] =
sentences.map(_.split(" ").toList)
def toWords(sentences: List[String]): List[String] =
sentences.flatMap(_.split(" ").toList)
Applicative !
def toWords(sentences: List[String]): List[List[[String]] =
sentences.map(_.split(" ").toList)
def toWords(sentences: List[String]): List[String] =
sentences.flatMap(_.split(" ").toList)
Applicative !
Fonctor + Applicative = Monad
def toWords(sentences: List[String]): List[List[[String]] =
sentences.map(_.split(" ").toList)
def toWords(sentences: List[String]): List[String] =
sentences.flatMap(_.split(" ").toList)
Monads !
Option[A]
List[A]Future[A]
Page[A]
Take away
● Monter son niveau d’abstration (ASM -> IMP -> OOP -> FUN !)
● Bannir null !!!
● Remplacer les ‘for’ par des fonctions de plus haut niveau
● Séparer le code technique de la logique métier
Le retour de la fonction, HumanTalks le 11/10/2016
Le retour de la fonction, HumanTalks le 11/10/2016

More Related Content

Viewers also liked

Socialgoal - Visionteractive
Socialgoal - VisionteractiveSocialgoal - Visionteractive
Socialgoal - Visionteractiveecemmertturk
 
TG2KM HHHC 9801 Kreatif dan Inovatif
TG2KM HHHC 9801 Kreatif dan InovatifTG2KM HHHC 9801 Kreatif dan Inovatif
TG2KM HHHC 9801 Kreatif dan InovatifFatinNorAlia
 
communication channels or modes
communication channels or modescommunication channels or modes
communication channels or modesGurpreet Singh
 
Madhyapradesh foodprocessingindustry-150706102716-lva1-app6891
Madhyapradesh foodprocessingindustry-150706102716-lva1-app6891Madhyapradesh foodprocessingindustry-150706102716-lva1-app6891
Madhyapradesh foodprocessingindustry-150706102716-lva1-app6891Jhimli Mukherjee
 
Rimagine Credentials_2016
Rimagine  Credentials_2016Rimagine  Credentials_2016
Rimagine Credentials_2016Vicky Wei
 
Getting a DUI is a Financial Wrecking Ball
Getting a DUI is a Financial Wrecking BallGetting a DUI is a Financial Wrecking Ball
Getting a DUI is a Financial Wrecking Ball Cost U Less Direct
 
6 Ways Your Brain Transforms Sound into Emotion
6 Ways Your Brain Transforms Sound into Emotion6 Ways Your Brain Transforms Sound into Emotion
6 Ways Your Brain Transforms Sound into EmotionAudiology Affiliates
 
Costos predeterminados equipo 8
Costos predeterminados equipo 8Costos predeterminados equipo 8
Costos predeterminados equipo 8Alfredo Hernandez
 

Viewers also liked (12)

Socialgoal - Visionteractive
Socialgoal - VisionteractiveSocialgoal - Visionteractive
Socialgoal - Visionteractive
 
BreeCS Example Report - All Deliveries
BreeCS Example Report - All DeliveriesBreeCS Example Report - All Deliveries
BreeCS Example Report - All Deliveries
 
Hardware
HardwareHardware
Hardware
 
TG2KM HHHC 9801 Kreatif dan Inovatif
TG2KM HHHC 9801 Kreatif dan InovatifTG2KM HHHC 9801 Kreatif dan Inovatif
TG2KM HHHC 9801 Kreatif dan Inovatif
 
communication channels or modes
communication channels or modescommunication channels or modes
communication channels or modes
 
Bentley
Bentley Bentley
Bentley
 
Madhyapradesh foodprocessingindustry-150706102716-lva1-app6891
Madhyapradesh foodprocessingindustry-150706102716-lva1-app6891Madhyapradesh foodprocessingindustry-150706102716-lva1-app6891
Madhyapradesh foodprocessingindustry-150706102716-lva1-app6891
 
Rimagine Credentials_2016
Rimagine  Credentials_2016Rimagine  Credentials_2016
Rimagine Credentials_2016
 
Getting a DUI is a Financial Wrecking Ball
Getting a DUI is a Financial Wrecking BallGetting a DUI is a Financial Wrecking Ball
Getting a DUI is a Financial Wrecking Ball
 
Love
LoveLove
Love
 
6 Ways Your Brain Transforms Sound into Emotion
6 Ways Your Brain Transforms Sound into Emotion6 Ways Your Brain Transforms Sound into Emotion
6 Ways Your Brain Transforms Sound into Emotion
 
Costos predeterminados equipo 8
Costos predeterminados equipo 8Costos predeterminados equipo 8
Costos predeterminados equipo 8
 

More from Loïc Knuchel

Scala bad practices, scala.io 2019
Scala bad practices, scala.io 2019Scala bad practices, scala.io 2019
Scala bad practices, scala.io 2019Loïc Knuchel
 
Mutation testing, enfin une bonne mesure de la qualité des tests ?, RivieraDe...
Mutation testing, enfin une bonne mesure de la qualité des tests ?, RivieraDe...Mutation testing, enfin une bonne mesure de la qualité des tests ?, RivieraDe...
Mutation testing, enfin une bonne mesure de la qualité des tests ?, RivieraDe...Loïc Knuchel
 
Comprendre la programmation fonctionnelle, Blend Web Mix le 02/11/2016
Comprendre la programmation fonctionnelle, Blend Web Mix le 02/11/2016Comprendre la programmation fonctionnelle, Blend Web Mix le 02/11/2016
Comprendre la programmation fonctionnelle, Blend Web Mix le 02/11/2016Loïc Knuchel
 
Ionic2, les développeurs web à l'assaut du mobile, BDX I/O le 21/10/2016
Ionic2, les développeurs web à l'assaut du mobile, BDX I/O le 21/10/2016Ionic2, les développeurs web à l'assaut du mobile, BDX I/O le 21/10/2016
Ionic2, les développeurs web à l'assaut du mobile, BDX I/O le 21/10/2016Loïc Knuchel
 
Ionic2 - the raise of web developer, Riviera DEV le 17/06/2016
Ionic2 - the raise of web developer, Riviera DEV le 17/06/2016Ionic2 - the raise of web developer, Riviera DEV le 17/06/2016
Ionic2 - the raise of web developer, Riviera DEV le 17/06/2016Loïc Knuchel
 
FP is coming... le 19/05/2016
FP is coming... le 19/05/2016FP is coming... le 19/05/2016
FP is coming... le 19/05/2016Loïc Knuchel
 
Programmation fonctionnelle en JavaScript
Programmation fonctionnelle en JavaScriptProgrammation fonctionnelle en JavaScript
Programmation fonctionnelle en JavaScriptLoïc Knuchel
 
Ionic Framework, L'avenir du mobile sera hybride, bdx.io le 16-10-2015
Ionic Framework, L'avenir du mobile sera hybride, bdx.io le 16-10-2015Ionic Framework, L'avenir du mobile sera hybride, bdx.io le 16-10-2015
Ionic Framework, L'avenir du mobile sera hybride, bdx.io le 16-10-2015Loïc Knuchel
 
Ionic, ce n'est pas que de l'UI, meetup PhoneGap le 25-05-2015
Ionic, ce n'est pas que de l'UI, meetup PhoneGap le 25-05-2015Ionic, ce n'est pas que de l'UI, meetup PhoneGap le 25-05-2015
Ionic, ce n'est pas que de l'UI, meetup PhoneGap le 25-05-2015Loïc Knuchel
 
Le développement mobile hybride sort du bois, Ch'ti JUG le 15-04-2015
Le développement mobile hybride sort du bois, Ch'ti JUG le 15-04-2015Le développement mobile hybride sort du bois, Ch'ti JUG le 15-04-2015
Le développement mobile hybride sort du bois, Ch'ti JUG le 15-04-2015Loïc Knuchel
 
Devoxx 2015, Atelier Ionic - 09/04/2015
Devoxx 2015, Atelier Ionic - 09/04/2015Devoxx 2015, Atelier Ionic - 09/04/2015
Devoxx 2015, Atelier Ionic - 09/04/2015Loïc Knuchel
 
Devoxx 2015, ionic chat
Devoxx 2015, ionic chatDevoxx 2015, ionic chat
Devoxx 2015, ionic chatLoïc Knuchel
 
Ionic HumanTalks - 11/03/2015
Ionic HumanTalks - 11/03/2015Ionic HumanTalks - 11/03/2015
Ionic HumanTalks - 11/03/2015Loïc Knuchel
 
Ionic bbl le 19 février 2015
Ionic bbl le 19 février 2015Ionic bbl le 19 février 2015
Ionic bbl le 19 février 2015Loïc Knuchel
 
Des maths et des recommandations - Devoxx 2014
Des maths et des recommandations - Devoxx 2014Des maths et des recommandations - Devoxx 2014
Des maths et des recommandations - Devoxx 2014Loïc Knuchel
 

More from Loïc Knuchel (15)

Scala bad practices, scala.io 2019
Scala bad practices, scala.io 2019Scala bad practices, scala.io 2019
Scala bad practices, scala.io 2019
 
Mutation testing, enfin une bonne mesure de la qualité des tests ?, RivieraDe...
Mutation testing, enfin une bonne mesure de la qualité des tests ?, RivieraDe...Mutation testing, enfin une bonne mesure de la qualité des tests ?, RivieraDe...
Mutation testing, enfin une bonne mesure de la qualité des tests ?, RivieraDe...
 
Comprendre la programmation fonctionnelle, Blend Web Mix le 02/11/2016
Comprendre la programmation fonctionnelle, Blend Web Mix le 02/11/2016Comprendre la programmation fonctionnelle, Blend Web Mix le 02/11/2016
Comprendre la programmation fonctionnelle, Blend Web Mix le 02/11/2016
 
Ionic2, les développeurs web à l'assaut du mobile, BDX I/O le 21/10/2016
Ionic2, les développeurs web à l'assaut du mobile, BDX I/O le 21/10/2016Ionic2, les développeurs web à l'assaut du mobile, BDX I/O le 21/10/2016
Ionic2, les développeurs web à l'assaut du mobile, BDX I/O le 21/10/2016
 
Ionic2 - the raise of web developer, Riviera DEV le 17/06/2016
Ionic2 - the raise of web developer, Riviera DEV le 17/06/2016Ionic2 - the raise of web developer, Riviera DEV le 17/06/2016
Ionic2 - the raise of web developer, Riviera DEV le 17/06/2016
 
FP is coming... le 19/05/2016
FP is coming... le 19/05/2016FP is coming... le 19/05/2016
FP is coming... le 19/05/2016
 
Programmation fonctionnelle en JavaScript
Programmation fonctionnelle en JavaScriptProgrammation fonctionnelle en JavaScript
Programmation fonctionnelle en JavaScript
 
Ionic Framework, L'avenir du mobile sera hybride, bdx.io le 16-10-2015
Ionic Framework, L'avenir du mobile sera hybride, bdx.io le 16-10-2015Ionic Framework, L'avenir du mobile sera hybride, bdx.io le 16-10-2015
Ionic Framework, L'avenir du mobile sera hybride, bdx.io le 16-10-2015
 
Ionic, ce n'est pas que de l'UI, meetup PhoneGap le 25-05-2015
Ionic, ce n'est pas que de l'UI, meetup PhoneGap le 25-05-2015Ionic, ce n'est pas que de l'UI, meetup PhoneGap le 25-05-2015
Ionic, ce n'est pas que de l'UI, meetup PhoneGap le 25-05-2015
 
Le développement mobile hybride sort du bois, Ch'ti JUG le 15-04-2015
Le développement mobile hybride sort du bois, Ch'ti JUG le 15-04-2015Le développement mobile hybride sort du bois, Ch'ti JUG le 15-04-2015
Le développement mobile hybride sort du bois, Ch'ti JUG le 15-04-2015
 
Devoxx 2015, Atelier Ionic - 09/04/2015
Devoxx 2015, Atelier Ionic - 09/04/2015Devoxx 2015, Atelier Ionic - 09/04/2015
Devoxx 2015, Atelier Ionic - 09/04/2015
 
Devoxx 2015, ionic chat
Devoxx 2015, ionic chatDevoxx 2015, ionic chat
Devoxx 2015, ionic chat
 
Ionic HumanTalks - 11/03/2015
Ionic HumanTalks - 11/03/2015Ionic HumanTalks - 11/03/2015
Ionic HumanTalks - 11/03/2015
 
Ionic bbl le 19 février 2015
Ionic bbl le 19 février 2015Ionic bbl le 19 février 2015
Ionic bbl le 19 février 2015
 
Des maths et des recommandations - Devoxx 2014
Des maths et des recommandations - Devoxx 2014Des maths et des recommandations - Devoxx 2014
Des maths et des recommandations - Devoxx 2014
 

Recently uploaded

GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
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
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
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
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
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
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfIdiosysTechnologies1
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 

Recently uploaded (20)

GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
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
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
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
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
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)
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdf
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 

Le retour de la fonction, HumanTalks le 11/10/2016

  • 1. Le retour de la fonction @loicknuchel
  • 2.
  • 4.
  • 5.
  • 6.
  • 7. for loop is everywhere function toUpperCase(list){ var ret = []; for(var i=0; i<list.length; i++){ ret[i] = list[i].toUpperCase(); } return ret; } var names = ['Finn', 'Rey', 'Poe']; console.log(toUpperCase(names)); // ['FINN', 'REY', 'POE']
  • 8. for loop is everywhere function toUpperCase(list){ var ret = []; for(var i=0; i<list.length; i++){ ret[i] = list[i].toUpperCase(); } return ret; } var names = ['Finn', 'Rey', 'Poe']; console.log(toUpperCase(names)); // ['FINN', 'REY', 'POE'] Boilerplate !!!
  • 9.
  • 10. Array.prototype.map = function(callback){ var array = this; var result = []; for(var i=0; i<array.length; i++){ result[i] = callback(array[i]); } return result; }; for loop is everywhere (High-order function)
  • 11. for loop is everywhere function toUpperCase(list){ return list.map(function(item){ return item.toUpperCase(); }); }
  • 12. for loop is everywhere function toUpperCase(list){ return list.map(item => item.toUpperCase()); }
  • 13. Séparation technique vs métier Array.prototype.map = function(callback){ var array = this; var result = []; for(var i=0; i<array.length; i++){ result[i] = callback(array[i]); } return result; }; list.map(item => item.toUpperCase()); Générique / Réutilisable Haut niveau d’abstraction Concis / Expressif Focalisé sur le domaine
  • 14. Scala collection API (en partie) def map[B](f: (A) => B): List[B] def filter(p: (A) => Boolean): List[A] def partition(p: (A) => Boolean): (List[A], List[A]) def zip[B](that: List[B]): List[(A, B)] def sliding(size: Int): Iterator[List[A]] def find(p: (A) => Boolean): Option[A] def exists(p: (A) => Boolean): Boolean def flatten[B]: List[B] def flatMap[B](f: (A) => List[B]): List[B] def groupBy[K](f: (A) => K): Map[K, List[A]] def grouped(size: Int): Iterator[List[A]] def fold[A1 >: A](z: A1)(op: (A1, A1) => A1): A1 def reduce[A1 >: A](op: (A1, A1) => A1): A1 def forall(p: (A) => Boolean): Boolean def take(n: Int): List[A] def drop(n: Int): List[A] def distinct: List[A]
  • 15.
  • 16. The billion dollar mistake ! function toUpperCase(list){ var ret = []; for(var i=0; i<list.length; i++){ ret[i] = list[i].toUpperCase(); } return ret; } Safe ?
  • 17. The billion dollar mistake ! function toUpperCase(list){ var ret = []; for(var i=0; i<list.length; i++){ ret[i] = list[i].toUpperCase(); } return ret; } Unsafe ! Cannot read property 'xxx' of undefined !!!
  • 18. The billion dollar mistake ! function toUpperCase(list){ var ret = []; for(var i=0; i<list.length; i++){ ret[i] = list[i].toUpperCase(); } return ret; } function toUpperCase(list){ var ret = []; if(Array.isArray(list)) { for(var i=0; i<list.length; i++){ if(typeof list[i] === 'string'){ ret[i] = list[i].toUpperCase(); } else { ret[i] = list[i]; } } } return ret; } Unsafe ! Unreadable !
  • 19. The billion dollar mistake ! function toUpperCase(list){ var ret = []; for(var i=0; i<list.length; i++){ ret[i] = list[i].toUpperCase(); } return ret; } function toUpperCase(list){ var ret = []; if(Array.isArray(list)) { for(var i=0; i<list.length; i++){ ret[i] = list[i].toUpperCase(); } } return ret; } function toUpperCase(list){ var ret = []; if(Array.isArray(list)) { for(var i=0; i<list.length; i++){ if(typeof list[i] === 'string'){ ret[i] = list[i].toUpperCase(); } else { ret[i] = list[i]; } } } return ret; } Unsafe ! Unreadable ! (not so) smart
  • 20.
  • 21. The billion dollar mistake ! // no null ! def toUpperCase(list: List[String]) = list.map(_.toUpperCase) def toUpperCase(list: List[Option[String]]) = list.map(_.map(_.toUpperCase))
  • 23. List.map() vs Option.map() ??? Fonctors !!!
  • 24. def toWords(sentences: List[String]): List[List[[String]] = sentences.map(_.split(" ").toList) def toWords(sentences: List[String]): List[String] = sentences.flatMap(_.split(" ").toList)
  • 25. def toWords(sentences: List[String]): List[List[[String]] = sentences.map(_.split(" ").toList) def toWords(sentences: List[String]): List[String] = sentences.flatMap(_.split(" ").toList) Applicative !
  • 26. def toWords(sentences: List[String]): List[List[[String]] = sentences.map(_.split(" ").toList) def toWords(sentences: List[String]): List[String] = sentences.flatMap(_.split(" ").toList) Applicative ! Fonctor + Applicative = Monad
  • 27. def toWords(sentences: List[String]): List[List[[String]] = sentences.map(_.split(" ").toList) def toWords(sentences: List[String]): List[String] = sentences.flatMap(_.split(" ").toList) Monads ! Option[A] List[A]Future[A] Page[A]
  • 28. Take away ● Monter son niveau d’abstration (ASM -> IMP -> OOP -> FUN !) ● Bannir null !!! ● Remplacer les ‘for’ par des fonctions de plus haut niveau ● Séparer le code technique de la logique métier