SlideShare une entreprise Scribd logo
1  sur  30
Télécharger pour lire hors ligne
FF TO FP
   Starring

       SCALA
AKKA 2
PLAY! FRAMEWORK 2
FP USING SCALA
   What is FP?
   Scala =?= FP
   In action...
WHAT IS FP?
FUNCTION == FIRST CLASS CITIZEN
WHAT IS A FUNCTION?
                      x                         eix + e-ix
        div(x, y) =                cos(x) =
                      y                 2
     Takes same Inputs. Produces same Outputs.
    No State change (Immutability). No Exceptions
Define behavior not tasks! Enables true composability.
    No Side-Effects == Referential Transparency
WHAT IS A FIRST CLASS CITIZEN?
A function is a tool like a structure or a primitive might
                             be.
  They encourage reuse and sharing. Thanks to their
                      composability.
 The simplest composition being the classical f o g     .
      But there are plenty of others... of course.
SCALA =?= FP
   Yes but mmmh...
> OO kept!
> Best of both worlds
> Imperative permitted
IMMUTABILITY
cs casUe(
 ae ls sr
  frtaeSrn,
  isNm:tig
  lsNm:tig
  ataeSrn,
  aeIt
  g:n
)

vlnota =Ue(ad" "erla,3)
 a oosb  sr"ny, ptel" 1

nota.isNm ="oh / BN !
 oosbfrtae na" / AG

vlna =nota.oyfrtae="oh,ae=2
 a oh  oosbcp(isNm  Na" g  )
NO EXCEPTIONS: OPTION
tatUi {
 ri tl
  dfpren(:tig:It
  e asItsSrn) n
}

vliIt=Ui.asIt"" / Wa d yuepc?
 a :n tlpren(a) / ht o o xet

tatUi {
 ri tl
  dfpren(:tig:Oto[n]
  e asItsSrn) pinIt
}

vliOto[n]=Ui.asIt"" / = Nn =>BtWY
 a :pinIt   tlpren(a) / = oe = u H?
vloe
 a n      =Ui.asIt"" / = Sm() ..Hywe
            tlpren(1) / = oe1  . e h
r' tetp?
 es h ye
EXCEPTIONS. BUT...
tatUi {
 ri tl
  dfpren(:tig:Ete[xeto,It
  e asItsSrn) ihrEcpin n]
}

vli
 a   =Ui.asIt"" /Lf(ubromtxeto(..)
       tlpren(a) /etNmeFraEcpin"."
)
vloe =Ui.asIt"" /Rgh1
 a n   tlpren(1) /it()
USE THE VALUES: MAPPER
vlaep:pinIt =Ui.asItrqetgt"g")
 a gOtOto[n]  tlpren(eus.e(ae)
vlueOt=aep.a((g:n)= Ue(sm" "n" ae )
 a srp  gOtmp aeIt > sr"oe, Oe, g)

/mpueteebdvle. ltssewt Ls
 /a s h me au.. e' e ih it
vlnosa =Ue(ad" "erla,3)
 a ootb   sr"ny, ptel" 1
vlna
 a oh   =Ue(na" "erla,2
          sr"oh, ptel" )

vluesLs[sr =Ls(ootb na)
 a sr:itUe]  itnosa, oh

vlae:itIt
 a gsLs[n]   =uesmp (:sr = uae)
               sr.a( uUe) > .g
vlaeSmlr
 a gsipe     =uesmp u= uae)
               sr.a(  > .g
vlaeEeSml
 a gsvnipe   =uesmp_ae
               sr.a(.g)
COMPOSABILITY: FLATMAPPER
tatRqet{
 ri eus
  dfgtkySrn)Oto[tig
  e e(e:tig:pinSrn]
}
vlaeau:pinSrn]
 a gVleOto[tig    =rqetgt"g"
                    eus.e(ae)
vlaep:pinIt
 a gOtOto[n]      =Ui.asItaeau)
                    tlpren(gVle
/ BN !
 / AG

vlaepOtOto[pinIt]=aeau.a(tlpren()
 a gOtp:pinOto[n]  gVlempUi.asIt_
)
/ BN !!
 / AG !

vlaeOto[n]
 a g:pinIt       =aeau.lta(tlpren
                   gVlefaMpUi.asI
t_)
 ()
/Go,ddû
 /od ij
ADD CONTROL: FILTER
vlaeau:pinSrn] =rqetgt"g"
 a gVleOto[tig  eus.e(ae)
vlaep:pinIt
 a gOtOto[n]   =aeau.lta(tlpren()
                gVlefaMpUi.asIt_)

vlalwd =aep.itr_> 1)
 a loe   gOtfle( = 8

vlna
 a oh   =alwdmpUe(na" "erla,_)/Nn
          loe.a(sr"oh, ptel" ) /oe
vlnota =alwdmpUe(ad" "erla,_)/Sm
 a oosb   loe.a(sr"ny, ptel" ) /oe
PUTTING THE PIECES TOGETHER
dfgtloeUe(eus:eus)Oto[sr ={
 e eAlwdsrrqetRqet:pinUe]
  vlfrtaep:pinSrn]=rqetgt"isNm"
  a isNmOtOto[tig   eus.e(frtae)
  vllsNmOtOto[tig =rqetgt"atae)
  a ataep:pinSrn]   eus.e(lsNm"
  vlaep:pinIt
  a gOtOto[n]     =rqetgt"g".lta(t
                    eus.e(ae)faMpU
i.asIt_)
 lpren()
  vlalwdgOtOto[n] =aep.itr_> 1)
  a loeAep:pinIt    gOtfle( = 8

    frtaep.lta {frtae=
     isNmOtfaMp     isNm >
      lsNmOtfaMp{lsNm =
       ataep.lta    atae >
        alwdgOtmp{alwdg =
         loeAep.a   loeAe >
          Ue(isNm,lsNm,alwdg)
           srfrtae atae loeAe
        }
      }
    }
}
FOR COMPREHENSION
dfgtsrcekg:n=Boen(eus:eus)=
 e eUe(hcAeIt>ola)rqetRqet
  fr{
  o
   frtae< rqetgt"isNm"
    isNm - eus.e(frtae)
   lsNm < rqetgt"atae)
    atae - eus.e(lsNm"
   aetig< rqetgt"g"
    gSrn - eus.e(ae)
   ae
    g    < Ui.asItaetig i cekg(g)
          - tlpren(gSrn) f hcAeae
  }yedUe(isNm,lsNm,ae
    il srfrtae atae g)

tp Rqet=MpSrn,Srn]
 ye eus  a[tig tig

vlalwdoDr :It= Boen
 a loeFroa n > ola           =(:n)> 2
                               _It =
vlgtloeUe :Rqet= Oto[sr
 a eAlwdsr eus > pinUe]      =gtsralwd
                               eUe(loeF
oDr)_
 roa

vlna
 a oh   =gtloeUe(
          eAlwdsr
            Mp
             a(
              "isNm">na"
               frtae-"oh,
              "atae-"erla,
               lsNm">ptel"
              "g">2
               ae-""
            )
          )
GET REAL?
Alt+Tab and code!
DISTRIBUTED ET AL. W/ AKKA
          Messages
           Actors
           Mailbox
        Fault-Tolerant
MESSAGES
         Sharing resource
             Synchronous
Message Passing Style to the rescue
Don't call, but send asynchronously
              Immutable
ACTORS
         Worker/Sender
React to message, Create message
           Hold a state
            Mutable
MAILBOX
                Queue of messages
Invoke dedicated actor when computing unit available
FAULT TOLERANT
             Actors hidden by reference
            Actors created hierarchically
Onion layers of supervision => restart, stop, bubble, ...
CODE IN PEACE
Back to the wild
PLAY! WITH THE WEB
Reactive and non-blocking
Asynchronous with no pain
       Scala & Java
  End-to-end integration
REACTIVE AND NON-BLOCKING
       Using JBoss Netty
React to content using Iteratees
ASYNCHRONOUS WITH NO PAIN
 Using Promise and Future...
 ... easily using Continuation
SCALA & JAVA
Scala for the core and API
    Java API available
END-TO-END INTEGRATION
From the database to the web client
 Reduce runtime time exceptions...
  ... Increase compile time errors
>> PLAY NEW
THANKS!
    (FOR NOT LEAVING)
chipchip: @noootsab
G+: andy.petrella
social coding: github / andypetrella
FB: RIP
Blog (TBC): http://ska-la.blogspot.be
Company: NextLab

      Come Back! @WAJUG
Ff to-fp

Contenu connexe

Tendances

The State of PHPUnit
The State of PHPUnitThe State of PHPUnit
The State of PHPUnit
Edorian
 
Creating windows store java script apps
Creating windows store java script appsCreating windows store java script apps
Creating windows store java script apps
Eugene Zharkov
 

Tendances (19)

The State of PHPUnit
The State of PHPUnitThe State of PHPUnit
The State of PHPUnit
 
CyberLink LabelPrint 2.5 Exploitation Process
CyberLink LabelPrint 2.5 Exploitation ProcessCyberLink LabelPrint 2.5 Exploitation Process
CyberLink LabelPrint 2.5 Exploitation Process
 
The State of PHPUnit
The State of PHPUnitThe State of PHPUnit
The State of PHPUnit
 
How to create a 3.2 billion dollar business in 20 minutes: combining AngularJ...
How to create a 3.2 billion dollar business in 20 minutes: combining AngularJ...How to create a 3.2 billion dollar business in 20 minutes: combining AngularJ...
How to create a 3.2 billion dollar business in 20 minutes: combining AngularJ...
 
What's New in PHP 5.5
What's New in PHP 5.5What's New in PHP 5.5
What's New in PHP 5.5
 
Build a custom (micro)framework with ZF2 Components (as building blocks)
Build a custom (micro)framework with ZF2 Components (as building blocks)Build a custom (micro)framework with ZF2 Components (as building blocks)
Build a custom (micro)framework with ZF2 Components (as building blocks)
 
Creating windows store java script apps
Creating windows store java script appsCreating windows store java script apps
Creating windows store java script apps
 
Go for the paranoid network programmer, 3rd edition
Go for the paranoid network programmer, 3rd editionGo for the paranoid network programmer, 3rd edition
Go for the paranoid network programmer, 3rd edition
 
Event Stream Processing with Multiple Threads
Event Stream Processing with Multiple ThreadsEvent Stream Processing with Multiple Threads
Event Stream Processing with Multiple Threads
 
Exploit Development: EzServer Buffer Overflow oleh Tom Gregory
Exploit Development: EzServer Buffer Overflow oleh Tom GregoryExploit Development: EzServer Buffer Overflow oleh Tom Gregory
Exploit Development: EzServer Buffer Overflow oleh Tom Gregory
 
[EN] Ada Lovelace Day 2014 - Tampon run
[EN] Ada Lovelace Day 2014  - Tampon run[EN] Ada Lovelace Day 2014  - Tampon run
[EN] Ada Lovelace Day 2014 - Tampon run
 
Remote Notifications
Remote NotificationsRemote Notifications
Remote Notifications
 
Diving deep into twig
Diving deep into twigDiving deep into twig
Diving deep into twig
 
Scala, just a better java?
Scala, just a better java?Scala, just a better java?
Scala, just a better java?
 
The Ring programming language version 1.5.3 book - Part 46 of 184
The Ring programming language version 1.5.3 book - Part 46 of 184The Ring programming language version 1.5.3 book - Part 46 of 184
The Ring programming language version 1.5.3 book - Part 46 of 184
 
20191116 custom operators in swift
20191116 custom operators in swift20191116 custom operators in swift
20191116 custom operators in swift
 
Javascript: The Important Bits
Javascript: The Important BitsJavascript: The Important Bits
Javascript: The Important Bits
 
API Development and Scala @ SoundCloud
API Development and Scala @ SoundCloudAPI Development and Scala @ SoundCloud
API Development and Scala @ SoundCloud
 
Functional pe(a)rls: Huey's zipper
Functional pe(a)rls: Huey's zipperFunctional pe(a)rls: Huey's zipper
Functional pe(a)rls: Huey's zipper
 

Similaire à Ff to-fp

Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
Loïc Descotte
 
Nginx Scripting - Extending Nginx Functionalities with Lua
Nginx Scripting - Extending Nginx Functionalities with LuaNginx Scripting - Extending Nginx Functionalities with Lua
Nginx Scripting - Extending Nginx Functionalities with Lua
Tony Fabeen
 
Devinsampa nginx-scripting
Devinsampa nginx-scriptingDevinsampa nginx-scripting
Devinsampa nginx-scripting
Tony Fabeen
 

Similaire à Ff to-fp (20)

Java 8 - project lambda
Java 8 - project lambdaJava 8 - project lambda
Java 8 - project lambda
 
A Backbone.js Tutorial for the Impatient - Part 1
A Backbone.js Tutorial for the Impatient - Part 1A Backbone.js Tutorial for the Impatient - Part 1
A Backbone.js Tutorial for the Impatient - Part 1
 
2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices
2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices
2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices
 
Hazelcast - In-Memory DataGrid
Hazelcast - In-Memory DataGridHazelcast - In-Memory DataGrid
Hazelcast - In-Memory DataGrid
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
 
Nginx Scripting - Extending Nginx Functionalities with Lua
Nginx Scripting - Extending Nginx Functionalities with LuaNginx Scripting - Extending Nginx Functionalities with Lua
Nginx Scripting - Extending Nginx Functionalities with Lua
 
Devinsampa nginx-scripting
Devinsampa nginx-scriptingDevinsampa nginx-scripting
Devinsampa nginx-scripting
 
Learn Frontend Testing
Learn Frontend TestingLearn Frontend Testing
Learn Frontend Testing
 
Presenting Seq for Node.js
Presenting Seq for Node.jsPresenting Seq for Node.js
Presenting Seq for Node.js
 
Music as data
Music as dataMusic as data
Music as data
 
Beginner workshop to angularjs presentation at Google
Beginner workshop to angularjs presentation at GoogleBeginner workshop to angularjs presentation at Google
Beginner workshop to angularjs presentation at Google
 
Introduction To Lisp
Introduction To LispIntroduction To Lisp
Introduction To Lisp
 
Operation Flow @ ChicagoRoboto
Operation Flow @ ChicagoRobotoOperation Flow @ ChicagoRoboto
Operation Flow @ ChicagoRoboto
 
From Javascript To Haskell
From Javascript To HaskellFrom Javascript To Haskell
From Javascript To Haskell
 
Making the most of 2.2
Making the most of 2.2Making the most of 2.2
Making the most of 2.2
 
Load-time Hacking using LD_PRELOAD
Load-time Hacking using LD_PRELOADLoad-time Hacking using LD_PRELOAD
Load-time Hacking using LD_PRELOAD
 
nescala 2013
nescala 2013nescala 2013
nescala 2013
 
XS Fun
XS FunXS Fun
XS Fun
 
Python quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung FuPython quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung Fu
 
FP Using ES6+ (Cheat Sheet)
FP Using ES6+ (Cheat Sheet)FP Using ES6+ (Cheat Sheet)
FP Using ES6+ (Cheat Sheet)
 

Plus de Andy Petrella

Plus de Andy Petrella (20)

Data Observability Best Pracices
Data Observability Best PracicesData Observability Best Pracices
Data Observability Best Pracices
 
How to Build a Global Data Mapping
How to Build a Global Data MappingHow to Build a Global Data Mapping
How to Build a Global Data Mapping
 
Interactive notebooks
Interactive notebooksInteractive notebooks
Interactive notebooks
 
Governance compliance
Governance   complianceGovernance   compliance
Governance compliance
 
Data science governance and GDPR
Data science governance and GDPRData science governance and GDPR
Data science governance and GDPR
 
Data science governance : what and how
Data science governance : what and howData science governance : what and how
Data science governance : what and how
 
Scala: the unpredicted lingua franca for data science
Scala: the unpredicted lingua franca  for data scienceScala: the unpredicted lingua franca  for data science
Scala: the unpredicted lingua franca for data science
 
Agile data science with scala
Agile data science with scalaAgile data science with scala
Agile data science with scala
 
Agile data science: Distributed, Interactive, Integrated, Semantic, Micro Ser...
Agile data science: Distributed, Interactive, Integrated, Semantic, Micro Ser...Agile data science: Distributed, Interactive, Integrated, Semantic, Micro Ser...
Agile data science: Distributed, Interactive, Integrated, Semantic, Micro Ser...
 
What is a distributed data science pipeline. how with apache spark and friends.
What is a distributed data science pipeline. how with apache spark and friends.What is a distributed data science pipeline. how with apache spark and friends.
What is a distributed data science pipeline. how with apache spark and friends.
 
Towards a rebirth of data science (by Data Fellas)
Towards a rebirth of data science (by Data Fellas)Towards a rebirth of data science (by Data Fellas)
Towards a rebirth of data science (by Data Fellas)
 
Distributed machine learning 101 using apache spark from a browser devoxx.b...
Distributed machine learning 101 using apache spark from a browser   devoxx.b...Distributed machine learning 101 using apache spark from a browser   devoxx.b...
Distributed machine learning 101 using apache spark from a browser devoxx.b...
 
Spark Summit Europe: Share and analyse genomic data at scale
Spark Summit Europe: Share and analyse genomic data at scaleSpark Summit Europe: Share and analyse genomic data at scale
Spark Summit Europe: Share and analyse genomic data at scale
 
Leveraging mesos as the ultimate distributed data science platform
Leveraging mesos as the ultimate distributed data science platformLeveraging mesos as the ultimate distributed data science platform
Leveraging mesos as the ultimate distributed data science platform
 
Data Enthusiasts London: Scalable and Interoperable data services. Applied to...
Data Enthusiasts London: Scalable and Interoperable data services. Applied to...Data Enthusiasts London: Scalable and Interoperable data services. Applied to...
Data Enthusiasts London: Scalable and Interoperable data services. Applied to...
 
Spark meetup london share and analyse genomic data at scale with spark, adam...
Spark meetup london  share and analyse genomic data at scale with spark, adam...Spark meetup london  share and analyse genomic data at scale with spark, adam...
Spark meetup london share and analyse genomic data at scale with spark, adam...
 
Distributed machine learning 101 using apache spark from the browser
Distributed machine learning 101 using apache spark from the browserDistributed machine learning 101 using apache spark from the browser
Distributed machine learning 101 using apache spark from the browser
 
Liège créative: Open Science
Liège créative: Open ScienceLiège créative: Open Science
Liège créative: Open Science
 
BioBankCloud: Machine Learning on Genomics + GA4GH @ Med at Scale
BioBankCloud: Machine Learning on Genomics + GA4GH  @ Med at ScaleBioBankCloud: Machine Learning on Genomics + GA4GH  @ Med at Scale
BioBankCloud: Machine Learning on Genomics + GA4GH @ Med at Scale
 
What is Distributed Computing, Why we use Apache Spark
What is Distributed Computing, Why we use Apache SparkWhat is Distributed Computing, Why we use Apache Spark
What is Distributed Computing, Why we use Apache Spark
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Dernier (20)

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
 
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)
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
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...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
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
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
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
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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, ...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Ff to-fp

  • 1. FF TO FP Starring SCALA AKKA 2 PLAY! FRAMEWORK 2
  • 2. FP USING SCALA What is FP? Scala =?= FP In action...
  • 3. WHAT IS FP? FUNCTION == FIRST CLASS CITIZEN
  • 4. WHAT IS A FUNCTION? x eix + e-ix div(x, y) = cos(x) = y 2 Takes same Inputs. Produces same Outputs. No State change (Immutability). No Exceptions Define behavior not tasks! Enables true composability. No Side-Effects == Referential Transparency
  • 5. WHAT IS A FIRST CLASS CITIZEN? A function is a tool like a structure or a primitive might be. They encourage reuse and sharing. Thanks to their composability. The simplest composition being the classical f o g . But there are plenty of others... of course.
  • 6. SCALA =?= FP Yes but mmmh... > OO kept! > Best of both worlds > Imperative permitted
  • 7. IMMUTABILITY cs casUe( ae ls sr frtaeSrn, isNm:tig lsNm:tig ataeSrn, aeIt g:n ) vlnota =Ue(ad" "erla,3) a oosb sr"ny, ptel" 1 nota.isNm ="oh / BN ! oosbfrtae na" / AG vlna =nota.oyfrtae="oh,ae=2 a oh oosbcp(isNm Na" g )
  • 8. NO EXCEPTIONS: OPTION tatUi { ri tl dfpren(:tig:It e asItsSrn) n } vliIt=Ui.asIt"" / Wa d yuepc? a :n tlpren(a) / ht o o xet tatUi { ri tl dfpren(:tig:Oto[n] e asItsSrn) pinIt } vliOto[n]=Ui.asIt"" / = Nn =>BtWY a :pinIt tlpren(a) / = oe = u H? vloe a n =Ui.asIt"" / = Sm() ..Hywe tlpren(1) / = oe1 . e h r' tetp? es h ye
  • 9. EXCEPTIONS. BUT... tatUi { ri tl dfpren(:tig:Ete[xeto,It e asItsSrn) ihrEcpin n] } vli a =Ui.asIt"" /Lf(ubromtxeto(..) tlpren(a) /etNmeFraEcpin"." ) vloe =Ui.asIt"" /Rgh1 a n tlpren(1) /it()
  • 10. USE THE VALUES: MAPPER vlaep:pinIt =Ui.asItrqetgt"g") a gOtOto[n] tlpren(eus.e(ae) vlueOt=aep.a((g:n)= Ue(sm" "n" ae ) a srp gOtmp aeIt > sr"oe, Oe, g) /mpueteebdvle. ltssewt Ls /a s h me au.. e' e ih it vlnosa =Ue(ad" "erla,3) a ootb sr"ny, ptel" 1 vlna a oh =Ue(na" "erla,2 sr"oh, ptel" ) vluesLs[sr =Ls(ootb na) a sr:itUe] itnosa, oh vlae:itIt a gsLs[n] =uesmp (:sr = uae) sr.a( uUe) > .g vlaeSmlr a gsipe =uesmp u= uae) sr.a( > .g vlaeEeSml a gsvnipe =uesmp_ae sr.a(.g)
  • 11. COMPOSABILITY: FLATMAPPER tatRqet{ ri eus dfgtkySrn)Oto[tig e e(e:tig:pinSrn] } vlaeau:pinSrn] a gVleOto[tig =rqetgt"g" eus.e(ae) vlaep:pinIt a gOtOto[n] =Ui.asItaeau) tlpren(gVle / BN ! / AG vlaepOtOto[pinIt]=aeau.a(tlpren() a gOtp:pinOto[n] gVlempUi.asIt_ ) / BN !! / AG ! vlaeOto[n] a g:pinIt =aeau.lta(tlpren gVlefaMpUi.asI t_) () /Go,ddû /od ij
  • 12. ADD CONTROL: FILTER vlaeau:pinSrn] =rqetgt"g" a gVleOto[tig eus.e(ae) vlaep:pinIt a gOtOto[n] =aeau.lta(tlpren() gVlefaMpUi.asIt_) vlalwd =aep.itr_> 1) a loe gOtfle( = 8 vlna a oh =alwdmpUe(na" "erla,_)/Nn loe.a(sr"oh, ptel" ) /oe vlnota =alwdmpUe(ad" "erla,_)/Sm a oosb loe.a(sr"ny, ptel" ) /oe
  • 13. PUTTING THE PIECES TOGETHER dfgtloeUe(eus:eus)Oto[sr ={ e eAlwdsrrqetRqet:pinUe] vlfrtaep:pinSrn]=rqetgt"isNm" a isNmOtOto[tig eus.e(frtae) vllsNmOtOto[tig =rqetgt"atae) a ataep:pinSrn] eus.e(lsNm" vlaep:pinIt a gOtOto[n] =rqetgt"g".lta(t eus.e(ae)faMpU i.asIt_) lpren() vlalwdgOtOto[n] =aep.itr_> 1) a loeAep:pinIt gOtfle( = 8 frtaep.lta {frtae= isNmOtfaMp isNm > lsNmOtfaMp{lsNm = ataep.lta atae > alwdgOtmp{alwdg = loeAep.a loeAe > Ue(isNm,lsNm,alwdg) srfrtae atae loeAe } } } }
  • 14. FOR COMPREHENSION dfgtsrcekg:n=Boen(eus:eus)= e eUe(hcAeIt>ola)rqetRqet fr{ o frtae< rqetgt"isNm" isNm - eus.e(frtae) lsNm < rqetgt"atae) atae - eus.e(lsNm" aetig< rqetgt"g" gSrn - eus.e(ae) ae g < Ui.asItaetig i cekg(g) - tlpren(gSrn) f hcAeae }yedUe(isNm,lsNm,ae il srfrtae atae g) tp Rqet=MpSrn,Srn] ye eus a[tig tig vlalwdoDr :It= Boen a loeFroa n > ola =(:n)> 2 _It = vlgtloeUe :Rqet= Oto[sr a eAlwdsr eus > pinUe] =gtsralwd eUe(loeF oDr)_ roa vlna a oh =gtloeUe( eAlwdsr Mp a( "isNm">na" frtae-"oh, "atae-"erla, lsNm">ptel" "g">2 ae-"" ) )
  • 15.
  • 17. DISTRIBUTED ET AL. W/ AKKA Messages Actors Mailbox Fault-Tolerant
  • 18. MESSAGES Sharing resource Synchronous Message Passing Style to the rescue Don't call, but send asynchronously Immutable
  • 19. ACTORS Worker/Sender React to message, Create message Hold a state Mutable
  • 20. MAILBOX Queue of messages Invoke dedicated actor when computing unit available
  • 21. FAULT TOLERANT Actors hidden by reference Actors created hierarchically Onion layers of supervision => restart, stop, bubble, ...
  • 22. CODE IN PEACE Back to the wild
  • 23. PLAY! WITH THE WEB Reactive and non-blocking Asynchronous with no pain Scala & Java End-to-end integration
  • 24. REACTIVE AND NON-BLOCKING Using JBoss Netty React to content using Iteratees
  • 25. ASYNCHRONOUS WITH NO PAIN Using Promise and Future... ... easily using Continuation
  • 26. SCALA & JAVA Scala for the core and API Java API available
  • 27. END-TO-END INTEGRATION From the database to the web client Reduce runtime time exceptions... ... Increase compile time errors
  • 29. THANKS! (FOR NOT LEAVING) chipchip: @noootsab G+: andy.petrella social coding: github / andypetrella FB: RIP Blog (TBC): http://ska-la.blogspot.be Company: NextLab Come Back! @WAJUG