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

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
 

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)

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
 

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

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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
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...apidays
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
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 educationjfdjdjcjdnsjd
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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 FresherRemote DBA Services
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
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
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 

Dernier (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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
+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...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
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
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 

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