SlideShare uma empresa Scribd logo
1 de 25
Baixar para ler offline
FLATMAP ZAT SHIT
Les monades expliquées aux geeks

      11h30 - 12h20 - Auditorium
FLATMAP ZAT SHIT
Les monades expliquées aux geeks




        François Sarradin
           Développeur λ

           @fsarradin
                                   27 au 29 mars
                                       2013
François Sarradin

 ● Développeur λ
 ● http://kerflyn.wordpress.com/

                                                     @fsarradin



                              ● "Je suis un bagger"
                              ● http://www.brownbaglunch.fr/

                             @bbl_fr
Entity x = getEntity1()
Entity y = getEntity2()
Entity z = x.get() + y.get()
Entity x = getEntity1()
 Entity y = getEntity2() Exception
 Entity z = x.get() + y.get()

                       null


Asynchrone
if                                          ()
                   (?                                  ch
                        !=                        c at
if (                 nu                     ...
     ? ==               ll
          null                         ry
               ) Entity ) = getEntity1()                               lly
                                     t                             ina
                           x
                                                     y . .. f
                                                  tr
                    Entity y = getEntity2()
           nu ll)
   (? !=            Entity z = x.get() + y.get()
                                            try
if                                               ..            . ca
                                                                    tch(




                                       sy
                         z ed                                            )
            ad oni




                                          nc
          re hr




                                            Th z .
                                             h
        Th nc




                                             ro
                                              re ed
                                               ni ..
         sy .




                                                ad
          ..
Entity x = getEntity1()
Entity y = getEntity2()
Entity z = x.get() + y.get()


                               * Conserve le
                                code métier
Agenda

 ●   Live coding / Scala 2.10
     ○ Exception
     ○ Asynchrone
 ●   Code review / Java 8
     ○Exception
 ●   Conclusion
Alice

       In
Bank-land
Alice
Service Web




Solde total ?
Architecture
3: PROFIT!                          Web

                                       JSON

2: ???                         BankService

                                        getAccount(b, n)
                                                             a:Account
                              AccountRepository
1: Get accounts
                  BankProxy       BankProxy           BankProxy



                   BGP          La Postale         Breizh Bank
def balanceByBank: String = { val balancesByBankJson:
   Iterable[String] = for ((bankName, accountNumbers
        <- ownerAccounts) yield { val balances:
         List[Double] = for (accountNumber <-
        accountNumbers.toList) yield
     getAccount(bankName,
   accountNumber
  ).balance                Démonstration
 s"""{"na
me":"$b
ankNam
                                   Scala 2.10
 e","b
   alan
     ce":
        "${b
          ala
              nce
                 s.
                 su
                m}
              "}
              "
            "              Code source sur Github
          "
          }
                        https://github.com/fsarradin/bankapp.git




                                                                   27 au 29 mars
                                                                       2013
Try[A]
 val ok = Try { 1 }
 ok: scala.util.Try[Int] = Success(1)


 val ko = Try { throw new Exception("#1") }
 ko: scala.util.Try[Nothing] = Failure(Exception: #1)
1 Try[A] 1 for-expression
 for { x <- ok } yield s"x = $x"
 res1: scala.util.Try[String] = Success(x = 1)


 for { x <- ko } yield s"x = $x"
 res2: scala.util.Try[String] = Failure(Exception: #1)
2 Try[A] 1 for-expression
 val   ok1:   Try[Int]   =   Success(1)
 val   ok2:   Try[Int]   =   Success(2)
 val   ko1:   Try[Int]   =   Failure(new Exception("#1"))
 val   ko2:   Try[Int]   =   Failure(new Exception("#2"))

 for { x <- ok1; y <- ok2 } yield x + y
 res1: scala.util.Try[Int] = Success(3)

 for { x <- ko1; y <- ok2 } yield x + y
 res2: scala.util.Try[String] = Failure(Exception: #1)

 for { x <- ko1; y <- ko2 } yield x + y
 res3: scala.util.Try[String] = Failure(Exception: #1)
def balanceByBank: String = { val balancesByBankJson:
   Iterable[String] = for ((bankName, accountNumbers
        <- ownerAccounts) yield { val balances:
         List[Double] = for (accountNumber <-
        accountNumbers.toList) yield
     getAccount(bankName,
   accountNumber
  ).balance                Démonstration
 s"""{"na
me":"$b
ankNam
                               Scala 2.10 : Try
 e","b
   alan
     ce":
        "${b
          ala
              nce
                 s.
                 su
                m}
              "}
              "
            "              Code source sur Github
          "
          }
                        https://github.com/fsarradin/bankapp.git




                                                                   27 au 29 mars
                                                                       2013
Future[A]
 val fshort: Future[Int] = Future { 1 }
 fshort: Future[Int] = ... // illico


 val flong: Future[Int] = Future { Thread.sleep(2000); 2 }
 flong: Future[Int] = ... // illico
Future[A] & for-expression
 for { x <- fshort } yield s"x = $x"
 res1: Future[String] ≈ Future("x = 1") // in fine


 for { x <- fshort; y <- flong } yield x + y
 res2: Future[Int] ≈ Future(3) // in fine
def balanceByBank: String = { val balancesByBankJson:
   Iterable[String] = for ((bankName, accountNumbers
        <- ownerAccounts) yield { val balances:
         List[Double] = for (accountNumber <-
        accountNumbers.toList) yield
     getAccount(bankName,
   accountNumber
  ).balance                Démonstration
 s"""{"na
me":"$b
ankNam
                             Scala 2.10 : Future
 e","b
   alan
     ce":
        "${b
          ala
              nce
                 s.
                 su
                m}
              "}
              "
            "              Code source sur Github
          "
          }
                        https://github.com/fsarradin/bankapp.git




                                                                   27 au 29 mars
                                                                       2013
Type monadique

      Try                                                          Future
   (exception)                                                   (asynchrone)

                                    Contexte

                                Monade
                 Aspect technique               Pureté fonctionnelle



    Option                 List                Reader                  ...
    (absence)        (non-déterminisme)   (depend. injection)
flatMap : opération monadique
for {                      m.map(x =>
  x <- m                     x + 1
}                          )
yield x + 1


for {                      m1.flatMap(x =>
  x <- m1                    m2.map(y =>
  y <- m2                      x + y
}                            )
yield x + y                )
def balanceByBank: String = { val balancesByBankJson:
   Iterable[String] = for ((bankName, accountNumbers
        <- ownerAccounts) yield { val balances:
         List[Double] = for (accountNumber <-
        accountNumbers.toList) yield
     getAccount(bankName,
   accountNumber
  ).balance               Démonstration
 s"""{"na
me":"$b
ankNam
                          Java 8 et les monades
 e","b
   alan
     ce":
        "${b
          ala
              nce
                 s.
                 su
                m}
              "}
              "
            "              Code source sur Github
          "
          }
                     https://github.com/fsarradin/bankapp-java.git




                                                                     27 au 29 mars
                                                                         2013
Conclusion

 ●   Code métier
     ○Peu de changement

 ●   Système de type
     ○Aspect technique (déclaratif)
     ○Composition métier/technique => code
     ○Validation => compilateur
Question ?

Mais conteúdo relacionado

Mais procurados

Collection v3
Collection v3Collection v3
Collection v3Sunil OS
 
The Ring programming language version 1.8 book - Part 107 of 202
The Ring programming language version 1.8 book - Part 107 of 202The Ring programming language version 1.8 book - Part 107 of 202
The Ring programming language version 1.8 book - Part 107 of 202Mahmoud Samir Fayed
 
Introduction to programming with dependent types in Scala
Introduction to programming with dependent types in ScalaIntroduction to programming with dependent types in Scala
Introduction to programming with dependent types in ScalaDmytro Mitin
 
Computer Vision using Ruby and libJIT - RubyConf 2009
Computer Vision using Ruby and libJIT - RubyConf 2009Computer Vision using Ruby and libJIT - RubyConf 2009
Computer Vision using Ruby and libJIT - RubyConf 2009Jan Wedekind
 
Objective-Cひとめぐり
Objective-CひとめぐりObjective-Cひとめぐり
Objective-CひとめぐりKenji Kinukawa
 
Lesson17: Functions Of Several Variables
Lesson17: Functions Of  Several  VariablesLesson17: Functions Of  Several  Variables
Lesson17: Functions Of Several VariablesMatthew Leingang
 
The Ring programming language version 1.9 book - Part 38 of 210
The Ring programming language version 1.9 book - Part 38 of 210The Ring programming language version 1.9 book - Part 38 of 210
The Ring programming language version 1.9 book - Part 38 of 210Mahmoud Samir Fayed
 
oop presentation note
oop presentation note oop presentation note
oop presentation note Atit Patumvan
 
Sceneform SDK на практиці - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019Sceneform SDK на практиці - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019Eugene Kurko
 
The Ring programming language version 1.2 book - Part 20 of 84
The Ring programming language version 1.2 book - Part 20 of 84The Ring programming language version 1.2 book - Part 20 of 84
The Ring programming language version 1.2 book - Part 20 of 84Mahmoud Samir Fayed
 
Functional "Life": parallel cellular automata and comonads
Functional "Life": parallel cellular automata and comonadsFunctional "Life": parallel cellular automata and comonads
Functional "Life": parallel cellular automata and comonadsAlexander Granin
 
JavaScript blast
JavaScript blastJavaScript blast
JavaScript blastdominion
 

Mais procurados (20)

ECMA 入门
ECMA 入门ECMA 入门
ECMA 入门
 
Learning from 6,000 projects mining specifications in the large
Learning from 6,000 projects   mining specifications in the largeLearning from 6,000 projects   mining specifications in the large
Learning from 6,000 projects mining specifications in the large
 
Collection v3
Collection v3Collection v3
Collection v3
 
Array notes
Array notesArray notes
Array notes
 
Sigma type
Sigma typeSigma type
Sigma type
 
The Ring programming language version 1.8 book - Part 107 of 202
The Ring programming language version 1.8 book - Part 107 of 202The Ring programming language version 1.8 book - Part 107 of 202
The Ring programming language version 1.8 book - Part 107 of 202
 
Introduction to programming with dependent types in Scala
Introduction to programming with dependent types in ScalaIntroduction to programming with dependent types in Scala
Introduction to programming with dependent types in Scala
 
Computer Vision using Ruby and libJIT - RubyConf 2009
Computer Vision using Ruby and libJIT - RubyConf 2009Computer Vision using Ruby and libJIT - RubyConf 2009
Computer Vision using Ruby and libJIT - RubyConf 2009
 
Composite Pattern
Composite PatternComposite Pattern
Composite Pattern
 
Objective-Cひとめぐり
Objective-CひとめぐりObjective-Cひとめぐり
Objective-Cひとめぐり
 
SVGo workshop
SVGo workshopSVGo workshop
SVGo workshop
 
Polynomial
PolynomialPolynomial
Polynomial
 
Lesson17: Functions Of Several Variables
Lesson17: Functions Of  Several  VariablesLesson17: Functions Of  Several  Variables
Lesson17: Functions Of Several Variables
 
The Ring programming language version 1.9 book - Part 38 of 210
The Ring programming language version 1.9 book - Part 38 of 210The Ring programming language version 1.9 book - Part 38 of 210
The Ring programming language version 1.9 book - Part 38 of 210
 
oop presentation note
oop presentation note oop presentation note
oop presentation note
 
My favorite slides
My favorite slidesMy favorite slides
My favorite slides
 
Sceneform SDK на практиці - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019Sceneform SDK на практиці - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019
 
The Ring programming language version 1.2 book - Part 20 of 84
The Ring programming language version 1.2 book - Part 20 of 84The Ring programming language version 1.2 book - Part 20 of 84
The Ring programming language version 1.2 book - Part 20 of 84
 
Functional "Life": parallel cellular automata and comonads
Functional "Life": parallel cellular automata and comonadsFunctional "Life": parallel cellular automata and comonads
Functional "Life": parallel cellular automata and comonads
 
JavaScript blast
JavaScript blastJavaScript blast
JavaScript blast
 

Semelhante a FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)

Functors, applicatives, monads
Functors, applicatives, monadsFunctors, applicatives, monads
Functors, applicatives, monadsrkaippully
 
Functional Concepts for OOP Developers
Functional Concepts for OOP DevelopersFunctional Concepts for OOP Developers
Functional Concepts for OOP Developersbrweber2
 
First-Class Patterns
First-Class PatternsFirst-Class Patterns
First-Class PatternsJohn De Goes
 
Gems of GameplayKit. UA Mobile 2017.
Gems of GameplayKit. UA Mobile 2017.Gems of GameplayKit. UA Mobile 2017.
Gems of GameplayKit. UA Mobile 2017.UA Mobile
 
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...Mozaic Works
 
Idioms in swift 2016 05c
Idioms in swift 2016 05cIdioms in swift 2016 05c
Idioms in swift 2016 05cKaz Yoshikawa
 
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014PyData
 
Truth, deduction, computation lecture g
Truth, deduction, computation   lecture gTruth, deduction, computation   lecture g
Truth, deduction, computation lecture gVlad Patryshev
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)gekiaruj
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...Philip Schwarz
 
13 - Scala. Dependent pair type (Σ-type)
13 - Scala. Dependent pair type (Σ-type)13 - Scala. Dependent pair type (Σ-type)
13 - Scala. Dependent pair type (Σ-type)Roman Brovko
 
Fp in scala part 2
Fp in scala part 2Fp in scala part 2
Fp in scala part 2Hang Zhao
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and ScalaFolding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and ScalaPhilip Schwarz
 
Class 29: Inheritance
Class 29: InheritanceClass 29: Inheritance
Class 29: InheritanceDavid Evans
 
High-Performance Haskell
High-Performance HaskellHigh-Performance Haskell
High-Performance HaskellJohan Tibell
 
โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1
โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1
โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1Little Tukta Lita
 
What is Algorithm - An Overview
What is Algorithm - An OverviewWhat is Algorithm - An Overview
What is Algorithm - An OverviewRamakant Soni
 
Machine-level Composition of Modularized Crosscutting Concerns
Machine-level Composition of Modularized Crosscutting ConcernsMachine-level Composition of Modularized Crosscutting Concerns
Machine-level Composition of Modularized Crosscutting Concernssaintiss
 

Semelhante a FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013) (20)

Functors, applicatives, monads
Functors, applicatives, monadsFunctors, applicatives, monads
Functors, applicatives, monads
 
Functional Concepts for OOP Developers
Functional Concepts for OOP DevelopersFunctional Concepts for OOP Developers
Functional Concepts for OOP Developers
 
First-Class Patterns
First-Class PatternsFirst-Class Patterns
First-Class Patterns
 
ATS Programming
ATS ProgrammingATS Programming
ATS Programming
 
Gems of GameplayKit. UA Mobile 2017.
Gems of GameplayKit. UA Mobile 2017.Gems of GameplayKit. UA Mobile 2017.
Gems of GameplayKit. UA Mobile 2017.
 
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...
 
Idioms in swift 2016 05c
Idioms in swift 2016 05cIdioms in swift 2016 05c
Idioms in swift 2016 05c
 
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
 
Truth, deduction, computation lecture g
Truth, deduction, computation   lecture gTruth, deduction, computation   lecture g
Truth, deduction, computation lecture g
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...
 
13 - Scala. Dependent pair type (Σ-type)
13 - Scala. Dependent pair type (Σ-type)13 - Scala. Dependent pair type (Σ-type)
13 - Scala. Dependent pair type (Σ-type)
 
Fp in scala part 2
Fp in scala part 2Fp in scala part 2
Fp in scala part 2
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and ScalaFolding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
 
Class 29: Inheritance
Class 29: InheritanceClass 29: Inheritance
Class 29: Inheritance
 
High-Performance Haskell
High-Performance HaskellHigh-Performance Haskell
High-Performance Haskell
 
โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1
โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1
โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1
 
Matlab
MatlabMatlab
Matlab
 
What is Algorithm - An Overview
What is Algorithm - An OverviewWhat is Algorithm - An Overview
What is Algorithm - An Overview
 
Machine-level Composition of Modularized Crosscutting Concerns
Machine-level Composition of Modularized Crosscutting ConcernsMachine-level Composition of Modularized Crosscutting Concerns
Machine-level Composition of Modularized Crosscutting Concerns
 

Mais de François Sarradin

Mais de François Sarradin (6)

Java (8) eXperiments - DevoxxFR 2016
Java (8) eXperiments - DevoxxFR 2016Java (8) eXperiments - DevoxxFR 2016
Java (8) eXperiments - DevoxxFR 2016
 
Java8 eXperiment - Normandy JUG
Java8 eXperiment - Normandy JUGJava8 eXperiment - Normandy JUG
Java8 eXperiment - Normandy JUG
 
Scala vs java 8
Scala vs java 8Scala vs java 8
Scala vs java 8
 
Java 8 Lambda
Java 8 LambdaJava 8 Lambda
Java 8 Lambda
 
JavaScript Core
JavaScript CoreJavaScript Core
JavaScript Core
 
Programmation Fonctionnelle
Programmation FonctionnelleProgrammation Fonctionnelle
Programmation Fonctionnelle
 

Último

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 

Último (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 

FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)

  • 1. FLATMAP ZAT SHIT Les monades expliquées aux geeks 11h30 - 12h20 - Auditorium
  • 2. FLATMAP ZAT SHIT Les monades expliquées aux geeks François Sarradin Développeur λ @fsarradin 27 au 29 mars 2013
  • 3. François Sarradin ● Développeur λ ● http://kerflyn.wordpress.com/ @fsarradin ● "Je suis un bagger" ● http://www.brownbaglunch.fr/ @bbl_fr
  • 4. Entity x = getEntity1() Entity y = getEntity2() Entity z = x.get() + y.get()
  • 5. Entity x = getEntity1() Entity y = getEntity2() Exception Entity z = x.get() + y.get() null Asynchrone
  • 6. if () (? ch != c at if ( nu ... ? == ll null ry ) Entity ) = getEntity1() lly t ina x y . .. f tr Entity y = getEntity2() nu ll) (? != Entity z = x.get() + y.get() try if .. . ca tch( sy z ed ) ad oni nc re hr Th z . h Th nc ro re ed ni .. sy . ad ..
  • 7. Entity x = getEntity1() Entity y = getEntity2() Entity z = x.get() + y.get() * Conserve le code métier
  • 8. Agenda ● Live coding / Scala 2.10 ○ Exception ○ Asynchrone ● Code review / Java 8 ○Exception ● Conclusion
  • 9. Alice In Bank-land
  • 10. Alice
  • 12. Architecture 3: PROFIT! Web JSON 2: ??? BankService getAccount(b, n) a:Account AccountRepository 1: Get accounts BankProxy BankProxy BankProxy BGP La Postale Breizh Bank
  • 13. def balanceByBank: String = { val balancesByBankJson: Iterable[String] = for ((bankName, accountNumbers <- ownerAccounts) yield { val balances: List[Double] = for (accountNumber <- accountNumbers.toList) yield getAccount(bankName, accountNumber ).balance Démonstration s"""{"na me":"$b ankNam Scala 2.10 e","b alan ce": "${b ala nce s. su m} "} " " Code source sur Github " } https://github.com/fsarradin/bankapp.git 27 au 29 mars 2013
  • 14. Try[A] val ok = Try { 1 } ok: scala.util.Try[Int] = Success(1) val ko = Try { throw new Exception("#1") } ko: scala.util.Try[Nothing] = Failure(Exception: #1)
  • 15. 1 Try[A] 1 for-expression for { x <- ok } yield s"x = $x" res1: scala.util.Try[String] = Success(x = 1) for { x <- ko } yield s"x = $x" res2: scala.util.Try[String] = Failure(Exception: #1)
  • 16. 2 Try[A] 1 for-expression val ok1: Try[Int] = Success(1) val ok2: Try[Int] = Success(2) val ko1: Try[Int] = Failure(new Exception("#1")) val ko2: Try[Int] = Failure(new Exception("#2")) for { x <- ok1; y <- ok2 } yield x + y res1: scala.util.Try[Int] = Success(3) for { x <- ko1; y <- ok2 } yield x + y res2: scala.util.Try[String] = Failure(Exception: #1) for { x <- ko1; y <- ko2 } yield x + y res3: scala.util.Try[String] = Failure(Exception: #1)
  • 17. def balanceByBank: String = { val balancesByBankJson: Iterable[String] = for ((bankName, accountNumbers <- ownerAccounts) yield { val balances: List[Double] = for (accountNumber <- accountNumbers.toList) yield getAccount(bankName, accountNumber ).balance Démonstration s"""{"na me":"$b ankNam Scala 2.10 : Try e","b alan ce": "${b ala nce s. su m} "} " " Code source sur Github " } https://github.com/fsarradin/bankapp.git 27 au 29 mars 2013
  • 18. Future[A] val fshort: Future[Int] = Future { 1 } fshort: Future[Int] = ... // illico val flong: Future[Int] = Future { Thread.sleep(2000); 2 } flong: Future[Int] = ... // illico
  • 19. Future[A] & for-expression for { x <- fshort } yield s"x = $x" res1: Future[String] ≈ Future("x = 1") // in fine for { x <- fshort; y <- flong } yield x + y res2: Future[Int] ≈ Future(3) // in fine
  • 20. def balanceByBank: String = { val balancesByBankJson: Iterable[String] = for ((bankName, accountNumbers <- ownerAccounts) yield { val balances: List[Double] = for (accountNumber <- accountNumbers.toList) yield getAccount(bankName, accountNumber ).balance Démonstration s"""{"na me":"$b ankNam Scala 2.10 : Future e","b alan ce": "${b ala nce s. su m} "} " " Code source sur Github " } https://github.com/fsarradin/bankapp.git 27 au 29 mars 2013
  • 21. Type monadique Try Future (exception) (asynchrone) Contexte Monade Aspect technique Pureté fonctionnelle Option List Reader ... (absence) (non-déterminisme) (depend. injection)
  • 22. flatMap : opération monadique for { m.map(x => x <- m x + 1 } ) yield x + 1 for { m1.flatMap(x => x <- m1 m2.map(y => y <- m2 x + y } ) yield x + y )
  • 23. def balanceByBank: String = { val balancesByBankJson: Iterable[String] = for ((bankName, accountNumbers <- ownerAccounts) yield { val balances: List[Double] = for (accountNumber <- accountNumbers.toList) yield getAccount(bankName, accountNumber ).balance Démonstration s"""{"na me":"$b ankNam Java 8 et les monades e","b alan ce": "${b ala nce s. su m} "} " " Code source sur Github " } https://github.com/fsarradin/bankapp-java.git 27 au 29 mars 2013
  • 24. Conclusion ● Code métier ○Peu de changement ● Système de type ○Aspect technique (déclaratif) ○Composition métier/technique => code ○Validation => compilateur