SlideShare une entreprise Scribd logo
1  sur  25
Télécharger pour lire hors ligne
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 ?

Contenu connexe

Tendances

oop presentation note
oop presentation note oop presentation note
oop presentation note
Atit Patumvan
 
JavaScript blast
JavaScript blastJavaScript blast
JavaScript blast
dominion
 

Tendances (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
 

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

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
 
High-Performance Haskell
High-Performance HaskellHigh-Performance Haskell
High-Performance Haskell
Johan Tibell
 
โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1
โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1
โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1
Little Tukta Lita
 

Similaire à 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
 

Plus de François Sarradin

Plus 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
 

Dernier

Dernier (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
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...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

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