SlideShare una empresa de Scribd logo
1 de 15
Descargar para leer sin conexión
LES CONCEPTS DE LA PROGRAMMATION
FONCTIONNELLE ILLUSTRÉS AVEC JAVA 8
Yannick Chartois / @ychartois
BODIL STOKKE
What Every Hipster Should Know About Functional
Programming
Vimeo / Parleys
QUESTION
Maintenant que nous allons avoir les lambdas, peut-on faire la
même chose en Java 8?
1. FIRST CLASS FUNCTION
Définition
“Les fonctions sont traitées par le langage
comme des valeurs de première classe.”
1. FIRST CLASS FUNCTION
Code:
Fnto<Srn,Srn >hlo=(tigs - "el "+s
ucin tig tig
el
Srn ) > hlo
;

Resultat:
hlo;
el
/ BsCnet$Lmd$@0e9
/ aeocps$aba1a9e2
/ ! BsCnet@0391
/ = aeocps3f99
hloapy"run);
el.pl(Eoa"
/ hloEoa
/ el run
2. HIGH ORDER FUNCTION
Définition
“C'est une fonction qui prend une ou plusieurs
fonctions comme entrée et/ou qui renvoie une
fonction”
2. HIGH ORDER FUNCTION
Code:
Fnto<Srn,Srn >tie Fnto<Srn,Srn >f){
ucin tig tig
wc( ucin tig tig
rtr (tigs - fapy fapys )
eun Srn ) > .pl( .pl() ;
}

Resultat:
tiehlo.pl(Eoa";
wc(el)apy"run)
/ hlohloEoa
/ el el run
3. FUNCTOR
Définition
“C'est une collection d'éléments X qui peut
s'appliquer une fonction f: X -> Y pour créer une
collection Y”
3. FUNCTOR - MAP
Code:
Ls<Srn >mp Fnto<Srn,Srn >f
it tig
a( ucin tig tig
,Ls<Srn >vle ){
it tig
aus
Ls<Srn >tRtr =nwAryit >)
it tig
oeun
e raLs< (;
fr Srn cret:vle ){
o( tig urn
aus
tRtr.d(fapycret )
oeunad .pl(urn) ;
}
rtr tRtr;
eun oeun
}

Resultat:
Ls<Srn >cns=
it tig
of
Ary.sit nwSrn[{jg,"eox,"aan" )
rasaLs( e tig]"u" dvx" jvoe} ;
mp s- stUprae) cns)
a(
> .opeCs(, of ;
/ [U,DVX,JVOE
/ JG EOX AAN]

Avec les Streams Java 8:
cnssra(.a(s- stUprae))clet Cletr.oit))
of.tem)mp
> .opeCs( .olc( olcostLs(
3. FUNCTOR - FILTER
Code:
Ls<Srn >fle(Fnto<Srn,Boen>f
it tig
itr ucin tig ola
,
Ls<Srn >vle ){
it tig
aus
Ls<Srn >tRtr =nwAryit >)
it tig
oeun
e raLs< (;
fr Srn cret:vle ){
o( tig urn
aus
i (fapycret )
f
.pl(urn)
tRtr.d(cret)
oeunad urn ;
}
rtr tRtr;
eun oeun
}

Resultat:
Ls<Srn >cns=
it tig
of
Ary.sit nwSrn[{jg,"eox,"aan" )
rasaLs( e tig]"u" dvx" jvoe} ;
fle( - scnan(j) cns ;
itrs > .otis"", of)
/ [u,jvoe
/ jg aan]

Avec les Streams Java 8:
cnssra(.itr s- scnan(j))cletCletr.oit)
of.tem)fle(
> .otis"" .olc(olcostLs()
4. COMBINATOR
Définition
“C'est une function qui définie une nouvelle
fonction à partir de ses arguments ou d'autre
combinators”
4. COMBINATOR - NULL COMBINATOR
Constat:
Ls<Srn >cns =Ary.sit nwSrn[
it tig
of2
rasaLs( e tig]
{jg,"eox,"aan" nl})
"u" dvx" jvoe, ul ;
mp s- stUprae) cns)
a(
> .opeCs(, of2;
/ Ecpini tra "an jv.agNlPitrxeto
/ xeto n hed mi" aaln.uloneEcpin

Code:
Fnto<Srn,Srn >nlCek Fnto<Srn,Srn >f){
ucin tig tig
ulhc( ucin tig tig
rtr (tigs - s= nl ?"ul :fapys;
eun Srn ) >
= ul
nl"
.pl()
}

Resultat:
mp nlCeks- stUprae),cns)
a( ulhc( > .opeCs() of2
/ [U,DVX,JVOE nl]
/ JG EOX AAN, ul
5. COMPOSITION
Définition
“Combine plusieurs fonctions pour créer une
nouvelle fonction”
5. COMPOSITION
Code:
Fnto<Srn,Srn >cmoe(Fnto<Srn,Srn >f,
ucin tig tig
ops
ucin tig tig
1
Fnto<Srn,Srn >f ){
ucin tig tig
2
rtr (tigs - f.pl(f.pl())
eun Srn ) > 1apy 2apys ;
}

Resultat:
Fnto<Srn,Srn >u =(tigs - stUprae)
ucin tig tig
p
Srn ) > .opeCs(;
Fnto<Srn,Srn >hlo=(tigs - "el "+s
ucin tig tig
el
Srn ) > hlo
;
u.pl(hloapy"run))
papy el.pl(Eoa" ;
cmoe u,hlo.pl(Eoa" ;
ops( p el)apy"run)
/ HLOEOA
/ EL RUN

Avec Java 8:
hloadhnu)apy"run)
el.nTe(p.pl(Eoa"
u.ops(el)apy"run)
pcmoehlo.pl(Eoa"
END !

LES SOURCES: PROGFONCJAVA8
TWITTER: @YCHARTOIS

Más contenido relacionado

La actualidad más candente

cpp1 : Quelques elements de base du C++
cpp1 : Quelques elements de base du C++cpp1 : Quelques elements de base du C++
cpp1 : Quelques elements de base du C++Abdoulaye Dieng
 
Initiation à l'algorithmique
Initiation à l'algorithmiqueInitiation à l'algorithmique
Initiation à l'algorithmiqueAbdoulaye Dieng
 
Cours python avancé
Cours python avancéCours python avancé
Cours python avancépierrepo
 
Chapitre 2: String en Java
Chapitre 2:  String en JavaChapitre 2:  String en Java
Chapitre 2: String en JavaAziz Darouichi
 
Chapitre8: Collections et Enumerations En Java
Chapitre8: Collections et Enumerations En JavaChapitre8: Collections et Enumerations En Java
Chapitre8: Collections et Enumerations En JavaAziz Darouichi
 
Annotation Java vs. Decorator Python
Annotation Java vs. Decorator PythonAnnotation Java vs. Decorator Python
Annotation Java vs. Decorator PythonDidier Plaindoux
 
Les fondamentaux du langage C
Les fondamentaux du langage CLes fondamentaux du langage C
Les fondamentaux du langage CAbdoulaye Dieng
 
Introduction à la programmation
Introduction à la programmationIntroduction à la programmation
Introduction à la programmationpierrepo
 
Python For Data Science - French Course
Python For Data Science - French CoursePython For Data Science - French Course
Python For Data Science - French CourseHaytam EL YOUSSFI
 
Développement informatique : Programmation fonctionnelle, décorateur et génér...
Développement informatique : Programmation fonctionnelle, décorateur et génér...Développement informatique : Programmation fonctionnelle, décorateur et génér...
Développement informatique : Programmation fonctionnelle, décorateur et génér...ECAM Brussels Engineering School
 

La actualidad más candente (18)

cpp1 : Quelques elements de base du C++
cpp1 : Quelques elements de base du C++cpp1 : Quelques elements de base du C++
cpp1 : Quelques elements de base du C++
 
Initiation à l'algorithmique
Initiation à l'algorithmiqueInitiation à l'algorithmique
Initiation à l'algorithmique
 
Cours python avancé
Cours python avancéCours python avancé
Cours python avancé
 
Chapitre 2: String en Java
Chapitre 2:  String en JavaChapitre 2:  String en Java
Chapitre 2: String en Java
 
Chapitre8: Collections et Enumerations En Java
Chapitre8: Collections et Enumerations En JavaChapitre8: Collections et Enumerations En Java
Chapitre8: Collections et Enumerations En Java
 
Formation python
Formation pythonFormation python
Formation python
 
Annotation Java vs. Decorator Python
Annotation Java vs. Decorator PythonAnnotation Java vs. Decorator Python
Annotation Java vs. Decorator Python
 
Playing With PHP 5.3
Playing With PHP 5.3Playing With PHP 5.3
Playing With PHP 5.3
 
Theme 7
Theme 7Theme 7
Theme 7
 
Les fondamentaux du langage C
Les fondamentaux du langage CLes fondamentaux du langage C
Les fondamentaux du langage C
 
Introduction à la programmation
Introduction à la programmationIntroduction à la programmation
Introduction à la programmation
 
Java SE 7
Java SE 7Java SE 7
Java SE 7
 
Python For Data Science - French Course
Python For Data Science - French CoursePython For Data Science - French Course
Python For Data Science - French Course
 
Python après 15 ans de JAVA
Python après 15 ans de JAVAPython après 15 ans de JAVA
Python après 15 ans de JAVA
 
Exceptions
ExceptionsExceptions
Exceptions
 
Langage Perl
Langage PerlLangage Perl
Langage Perl
 
Développement informatique : Programmation fonctionnelle, décorateur et génér...
Développement informatique : Programmation fonctionnelle, décorateur et génér...Développement informatique : Programmation fonctionnelle, décorateur et génér...
Développement informatique : Programmation fonctionnelle, décorateur et génér...
 
Formation python
Formation pythonFormation python
Formation python
 

Destacado

Scopriariannabyskemalog babel
Scopriariannabyskemalog babelScopriariannabyskemalog babel
Scopriariannabyskemalog babelBabel
 
Babelinfograficamonamourisa2014
Babelinfograficamonamourisa2014Babelinfograficamonamourisa2014
Babelinfograficamonamourisa2014Babel
 
Concepts of functional programming
Concepts of functional programmingConcepts of functional programming
Concepts of functional programmingYannick Chartois
 
Les concepts de la programmation fonctionnelle illustrés avec java 8
Les concepts de la programmation fonctionnelle illustrés avec java 8Les concepts de la programmation fonctionnelle illustrés avec java 8
Les concepts de la programmation fonctionnelle illustrés avec java 8Yannick Chartois
 
Owl rescue nov 2013
Owl rescue nov 2013Owl rescue nov 2013
Owl rescue nov 2013Kasumioda
 
11 soalan sebelum beli theme wordpress
11 soalan sebelum beli theme wordpress11 soalan sebelum beli theme wordpress
11 soalan sebelum beli theme wordpressafri2
 
Уютненько о Яндекс Директ
Уютненько о Яндекс ДиректУютненько о Яндекс Директ
Уютненько о Яндекс ДиректFelix315
 
Nova Marketing. Presentation.
Nova Marketing. Presentation.Nova Marketing. Presentation.
Nova Marketing. Presentation.Felix315
 

Destacado (13)

Scopriariannabyskemalog babel
Scopriariannabyskemalog babelScopriariannabyskemalog babel
Scopriariannabyskemalog babel
 
Babelinfograficamonamourisa2014
Babelinfograficamonamourisa2014Babelinfograficamonamourisa2014
Babelinfograficamonamourisa2014
 
Multi Recharge Company
Multi Recharge CompanyMulti Recharge Company
Multi Recharge Company
 
Concepts of functional programming
Concepts of functional programmingConcepts of functional programming
Concepts of functional programming
 
Les concepts de la programmation fonctionnelle illustrés avec java 8
Les concepts de la programmation fonctionnelle illustrés avec java 8Les concepts de la programmation fonctionnelle illustrés avec java 8
Les concepts de la programmation fonctionnelle illustrés avec java 8
 
Gravity: A Love Story
Gravity: A Love StoryGravity: A Love Story
Gravity: A Love Story
 
Owl rescue nov 2013
Owl rescue nov 2013Owl rescue nov 2013
Owl rescue nov 2013
 
Certifications Java
Certifications JavaCertifications Java
Certifications Java
 
My profile
My profileMy profile
My profile
 
11 soalan sebelum beli theme wordpress
11 soalan sebelum beli theme wordpress11 soalan sebelum beli theme wordpress
11 soalan sebelum beli theme wordpress
 
Уютненько о Яндекс Директ
Уютненько о Яндекс ДиректУютненько о Яндекс Директ
Уютненько о Яндекс Директ
 
Nova Marketing. Presentation.
Nova Marketing. Presentation.Nova Marketing. Presentation.
Nova Marketing. Presentation.
 
Domain Name System
Domain Name SystemDomain Name System
Domain Name System
 

Similar a Les concepts de la programmation fonctionnelle illustrés avec Java 8

Introduction à ERRest
Introduction à ERRestIntroduction à ERRest
Introduction à ERRestWO Community
 
Quelle place pour le framework Rails dans le développement d'application web
Quelle place pour le framework Rails dans le développement d'application webQuelle place pour le framework Rails dans le développement d'application web
Quelle place pour le framework Rails dans le développement d'application web5pidou
 
Java 8-streams-collectors-patterns
Java 8-streams-collectors-patternsJava 8-streams-collectors-patterns
Java 8-streams-collectors-patternsJosé Paumard
 
Analyse statique et applications
Analyse statique et applicationsAnalyse statique et applications
Analyse statique et applicationsDamien Seguy
 
Améliorations dans Java depuis la version 5
Améliorations dans Java depuis la version 5Améliorations dans Java depuis la version 5
Améliorations dans Java depuis la version 5Mamadou Oury Ba
 
Exploiter php 5
Exploiter php 5Exploiter php 5
Exploiter php 5halleck45
 
De java à swift en 2 temps trois mouvements
De java à swift en 2 temps trois mouvementsDe java à swift en 2 temps trois mouvements
De java à swift en 2 temps trois mouvementsDidier Plaindoux
 
201303 - Java8
201303 - Java8201303 - Java8
201303 - Java8lyonjug
 
Solr overview presentation
Solr overview presentationSolr overview presentation
Solr overview presentationspy-seth
 
Gatling Tool in Action at DevoxxFR 2012
Gatling Tool in Action at DevoxxFR 2012Gatling Tool in Action at DevoxxFR 2012
Gatling Tool in Action at DevoxxFR 2012slandelle
 
Librairies Java qui changent la vie
Librairies Java qui changent la vieLibrairies Java qui changent la vie
Librairies Java qui changent la viecluelessjoe
 
Introduction au langage Go
Introduction au langage GoIntroduction au langage Go
Introduction au langage GoSylvain Wallez
 
Python et la persistance de données — initiation python 1.5
Python et la persistance de données — initiation python 1.5Python et la persistance de données — initiation python 1.5
Python et la persistance de données — initiation python 1.5Abib Faye
 

Similar a Les concepts de la programmation fonctionnelle illustrés avec Java 8 (20)

Drools
DroolsDrools
Drools
 
Introduction à ERRest
Introduction à ERRestIntroduction à ERRest
Introduction à ERRest
 
Spring 3.0
Spring 3.0Spring 3.0
Spring 3.0
 
Les Threads.ppt
Les Threads.pptLes Threads.ppt
Les Threads.ppt
 
Quelle place pour le framework Rails dans le développement d'application web
Quelle place pour le framework Rails dans le développement d'application webQuelle place pour le framework Rails dans le développement d'application web
Quelle place pour le framework Rails dans le développement d'application web
 
Cours php
Cours phpCours php
Cours php
 
Java 8-streams-collectors-patterns
Java 8-streams-collectors-patternsJava 8-streams-collectors-patterns
Java 8-streams-collectors-patterns
 
Analyse statique et applications
Analyse statique et applicationsAnalyse statique et applications
Analyse statique et applications
 
Améliorations dans Java depuis la version 5
Améliorations dans Java depuis la version 5Améliorations dans Java depuis la version 5
Améliorations dans Java depuis la version 5
 
Exploiter php 5
Exploiter php 5Exploiter php 5
Exploiter php 5
 
De java à swift en 2 temps trois mouvements
De java à swift en 2 temps trois mouvementsDe java à swift en 2 temps trois mouvements
De java à swift en 2 temps trois mouvements
 
201303 - Java8
201303 - Java8201303 - Java8
201303 - Java8
 
Solr overview presentation
Solr overview presentationSolr overview presentation
Solr overview presentation
 
Gatling Tool in Action at DevoxxFR 2012
Gatling Tool in Action at DevoxxFR 2012Gatling Tool in Action at DevoxxFR 2012
Gatling Tool in Action at DevoxxFR 2012
 
Nouveautés de java 8
Nouveautés de java 8Nouveautés de java 8
Nouveautés de java 8
 
Presentation JPA
Presentation JPAPresentation JPA
Presentation JPA
 
Librairies Java qui changent la vie
Librairies Java qui changent la vieLibrairies Java qui changent la vie
Librairies Java qui changent la vie
 
Introduction au langage Go
Introduction au langage GoIntroduction au langage Go
Introduction au langage Go
 
Python et la persistance de données — initiation python 1.5
Python et la persistance de données — initiation python 1.5Python et la persistance de données — initiation python 1.5
Python et la persistance de données — initiation python 1.5
 
Drools et les moteurs de règles
Drools et les moteurs de règlesDrools et les moteurs de règles
Drools et les moteurs de règles
 

Les concepts de la programmation fonctionnelle illustrés avec Java 8

  • 1. LES CONCEPTS DE LA PROGRAMMATION FONCTIONNELLE ILLUSTRÉS AVEC JAVA 8 Yannick Chartois / @ychartois
  • 2. BODIL STOKKE What Every Hipster Should Know About Functional Programming Vimeo / Parleys
  • 3. QUESTION Maintenant que nous allons avoir les lambdas, peut-on faire la même chose en Java 8?
  • 4. 1. FIRST CLASS FUNCTION Définition “Les fonctions sont traitées par le langage comme des valeurs de première classe.”
  • 5. 1. FIRST CLASS FUNCTION Code: Fnto<Srn,Srn >hlo=(tigs - "el "+s ucin tig tig el Srn ) > hlo ; Resultat: hlo; el / BsCnet$Lmd$@0e9 / aeocps$aba1a9e2 / ! BsCnet@0391 / = aeocps3f99 hloapy"run); el.pl(Eoa" / hloEoa / el run
  • 6. 2. HIGH ORDER FUNCTION Définition “C'est une fonction qui prend une ou plusieurs fonctions comme entrée et/ou qui renvoie une fonction”
  • 7. 2. HIGH ORDER FUNCTION Code: Fnto<Srn,Srn >tie Fnto<Srn,Srn >f){ ucin tig tig wc( ucin tig tig rtr (tigs - fapy fapys ) eun Srn ) > .pl( .pl() ; } Resultat: tiehlo.pl(Eoa"; wc(el)apy"run) / hlohloEoa / el el run
  • 8. 3. FUNCTOR Définition “C'est une collection d'éléments X qui peut s'appliquer une fonction f: X -> Y pour créer une collection Y”
  • 9. 3. FUNCTOR - MAP Code: Ls<Srn >mp Fnto<Srn,Srn >f it tig a( ucin tig tig ,Ls<Srn >vle ){ it tig aus Ls<Srn >tRtr =nwAryit >) it tig oeun e raLs< (; fr Srn cret:vle ){ o( tig urn aus tRtr.d(fapycret ) oeunad .pl(urn) ; } rtr tRtr; eun oeun } Resultat: Ls<Srn >cns= it tig of Ary.sit nwSrn[{jg,"eox,"aan" ) rasaLs( e tig]"u" dvx" jvoe} ; mp s- stUprae) cns) a( > .opeCs(, of ; / [U,DVX,JVOE / JG EOX AAN] Avec les Streams Java 8: cnssra(.a(s- stUprae))clet Cletr.oit)) of.tem)mp > .opeCs( .olc( olcostLs(
  • 10. 3. FUNCTOR - FILTER Code: Ls<Srn >fle(Fnto<Srn,Boen>f it tig itr ucin tig ola , Ls<Srn >vle ){ it tig aus Ls<Srn >tRtr =nwAryit >) it tig oeun e raLs< (; fr Srn cret:vle ){ o( tig urn aus i (fapycret ) f .pl(urn) tRtr.d(cret) oeunad urn ; } rtr tRtr; eun oeun } Resultat: Ls<Srn >cns= it tig of Ary.sit nwSrn[{jg,"eox,"aan" ) rasaLs( e tig]"u" dvx" jvoe} ; fle( - scnan(j) cns ; itrs > .otis"", of) / [u,jvoe / jg aan] Avec les Streams Java 8: cnssra(.itr s- scnan(j))cletCletr.oit) of.tem)fle( > .otis"" .olc(olcostLs()
  • 11. 4. COMBINATOR Définition “C'est une function qui définie une nouvelle fonction à partir de ses arguments ou d'autre combinators”
  • 12. 4. COMBINATOR - NULL COMBINATOR Constat: Ls<Srn >cns =Ary.sit nwSrn[ it tig of2 rasaLs( e tig] {jg,"eox,"aan" nl}) "u" dvx" jvoe, ul ; mp s- stUprae) cns) a( > .opeCs(, of2; / Ecpini tra "an jv.agNlPitrxeto / xeto n hed mi" aaln.uloneEcpin Code: Fnto<Srn,Srn >nlCek Fnto<Srn,Srn >f){ ucin tig tig ulhc( ucin tig tig rtr (tigs - s= nl ?"ul :fapys; eun Srn ) > = ul nl" .pl() } Resultat: mp nlCeks- stUprae),cns) a( ulhc( > .opeCs() of2 / [U,DVX,JVOE nl] / JG EOX AAN, ul
  • 13. 5. COMPOSITION Définition “Combine plusieurs fonctions pour créer une nouvelle fonction”
  • 14. 5. COMPOSITION Code: Fnto<Srn,Srn >cmoe(Fnto<Srn,Srn >f, ucin tig tig ops ucin tig tig 1 Fnto<Srn,Srn >f ){ ucin tig tig 2 rtr (tigs - f.pl(f.pl()) eun Srn ) > 1apy 2apys ; } Resultat: Fnto<Srn,Srn >u =(tigs - stUprae) ucin tig tig p Srn ) > .opeCs(; Fnto<Srn,Srn >hlo=(tigs - "el "+s ucin tig tig el Srn ) > hlo ; u.pl(hloapy"run)) papy el.pl(Eoa" ; cmoe u,hlo.pl(Eoa" ; ops( p el)apy"run) / HLOEOA / EL RUN Avec Java 8: hloadhnu)apy"run) el.nTe(p.pl(Eoa" u.ops(el)apy"run) pcmoehlo.pl(Eoa"
  • 15. END ! LES SOURCES: PROGFONCJAVA8 TWITTER: @YCHARTOIS