SlideShare ist ein Scribd-Unternehmen logo
1 von 25
Downloaden Sie, um offline zu lesen
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 ?

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Ähnlich wie FLATMAP ZAT SHIT Les monades expliquées aux geeks

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
 

Ähnlich wie FLATMAP ZAT SHIT Les monades expliquées aux geeks (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
 

Mehr von François Sarradin

Mehr von 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
 

Kürzlich hochgeladen

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
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
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 

Kürzlich hochgeladen (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
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...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

FLATMAP ZAT SHIT Les monades expliquées aux geeks

  • 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