FF TO FP   Starring       SCALAAKKA 2PLAY! 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) =  ...
WHAT IS A FIRST CLASS CITIZEN?A function is a tool like a structure or a primitive might                             be.  ...
SCALA =?= FP   Yes but mmmh...> OO kept!> Best of both worlds> Imperative permitted
IMMUTABILITYcs casUe( ae ls sr  frtaeSrn,  isNm:tig  lsNm:tig  ataeSrn,  aeIt  g:n)vlnota =Ue(ad" "erla,3) a oosb  sr"ny, ...
NO EXCEPTIONS: OPTIONtatUi { ri tl  dfpren(:tig:It  e asItsSrn) n}vliIt=Ui.asIt"" / Wa d yuepc? a :n tlpren(a) / ht o o xe...
EXCEPTIONS. BUT...tatUi { ri tl  dfpren(:tig:Ete[xeto,It  e asItsSrn) ihrEcpin n]}vli a   =Ui.asIt"" /Lf(ubromtxeto(..)   ...
USE THE VALUES: MAPPERvlaep:pinIt =Ui.asItrqetgt"g") a gOtOto[n]  tlpren(eus.e(ae)vlueOt=aep.a((g:n)= Ue(sm" "n" ae ) a sr...
COMPOSABILITY: FLATMAPPERtatRqet{ ri eus  dfgtkySrn)Oto[tig  e e(e:tig:pinSrn]}vlaeau:pinSrn] a gVleOto[tig    =rqetgt"g" ...
ADD CONTROL: FILTERvlaeau:pinSrn] =rqetgt"g" a gVleOto[tig  eus.e(ae)vlaep:pinIt a gOtOto[n]   =aeau.lta(tlpren()         ...
PUTTING THE PIECES TOGETHERdfgtloeUe(eus:eus)Oto[sr ={ e eAlwdsrrqetRqet:pinUe]  vlfrtaep:pinSrn]=rqetgt"isNm"  a isNmOtOt...
FOR COMPREHENSIONdfgtsrcekg:n=Boen(eus:eus)= e eUe(hcAeIt>ola)rqetRqet  fr{  o   frtae< rqetgt"isNm"    isNm - eus.e(frtae...
GET REAL?Alt+Tab and code!
DISTRIBUTED ET AL. W/ AKKA          Messages           Actors           Mailbox        Fault-Tolerant
MESSAGES         Sharing resource             SynchronousMessage Passing Style to the rescueDont call, but send asynchrono...
ACTORS         Worker/SenderReact to message, Create message           Hold a state            Mutable
MAILBOX                Queue of messagesInvoke dedicated actor when computing unit available
FAULT TOLERANT             Actors hidden by reference            Actors created hierarchicallyOnion layers of supervision ...
CODE IN PEACEBack to the wild
PLAY! WITH THE WEBReactive and non-blockingAsynchronous with no pain       Scala & Java  End-to-end integration
REACTIVE AND NON-BLOCKING       Using JBoss NettyReact to content using Iteratees
ASYNCHRONOUS WITH NO PAIN Using Promise and Future... ... easily using Continuation
SCALA & JAVAScala for the core and API    Java API available
END-TO-END INTEGRATIONFrom the database to the web client Reduce runtime time exceptions...  ... Increase compile time err...
>> PLAY NEW
THANKS!    (FOR NOT LEAVING)chipchip: @noootsabG+: andy.petrellasocial coding: github / andypetrellaFB: RIPBlog (TBC): htt...
Ff to-fp
Ff to-fp
Upcoming SlideShare
Loading in …5
×

Ff to-fp

690 views

Published on

A talk about FP... giving some first impression about it using Scala, useful use cases with Akka and web one... using Play 2.0

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
690
On SlideShare
0
From Embeds
0
Number of Embeds
57
Actions
Shares
0
Downloads
6
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Ff to-fp

  1. 1. FF TO FP Starring SCALAAKKA 2PLAY! FRAMEWORK 2
  2. 2. FP USING SCALA What is FP? Scala =?= FP In action...
  3. 3. WHAT IS FP?FUNCTION == FIRST CLASS CITIZEN
  4. 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 ExceptionsDefine behavior not tasks! Enables true composability. No Side-Effects == Referential Transparency
  5. 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. 6. SCALA =?= FP Yes but mmmh...> OO kept!> Best of both worlds> Imperative permitted
  7. 7. IMMUTABILITYcs casUe( ae ls sr frtaeSrn, isNm:tig lsNm:tig ataeSrn, aeIt g:n)vlnota =Ue(ad" "erla,3) a oosb sr"ny, ptel" 1nota.isNm ="oh / BN ! oosbfrtae na" / AGvlna =nota.oyfrtae="oh,ae=2 a oh oosbcp(isNm Na" g )
  8. 8. NO EXCEPTIONS: OPTIONtatUi { ri tl dfpren(:tig:It e asItsSrn) n}vliIt=Ui.asIt"" / Wa d yuepc? a :n tlpren(a) / ht o o xettatUi { 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 hr tetp? es h ye
  9. 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. 10. USE THE VALUES: MAPPERvlaep: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 itvlnosa =Ue(ad" "erla,3) a ootb sr"ny, ptel" 1vlna a oh =Ue(na" "erla,2 sr"oh, ptel" )vluesLs[sr =Ls(ootb na) a sr:itUe] itnosa, ohvlae:itIt a gsLs[n] =uesmp (:sr = uae) sr.a( uUe) > .gvlaeSmlr a gsipe =uesmp u= uae) sr.a( > .gvlaeEeSml a gsvnipe =uesmp_ae sr.a(.g)
  11. 11. COMPOSABILITY: FLATMAPPERtatRqet{ 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 ! / AGvlaepOtOto[pinIt]=aeau.a(tlpren() a gOtp:pinOto[n] gVlempUi.asIt_)/ BN !! / AG !vlaeOto[n] a g:pinIt =aeau.lta(tlpren gVlefaMpUi.asIt_) ()/Go,ddû /od ij
  12. 12. ADD CONTROL: FILTERvlaeau: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( = 8vlna a oh =alwdmpUe(na" "erla,_)/Nn loe.a(sr"oh, ptel" ) /oevlnota =alwdmpUe(ad" "erla,_)/Sm a oosb loe.a(sr"ny, ptel" ) /oe
  13. 13. PUTTING THE PIECES TOGETHERdfgtloeUe(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)faMpUi.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. 14. FOR COMPREHENSIONdfgtsrcekg: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 tigvlalwdoDr :It= Boen a loeFroa n > ola =(:n)> 2 _It =vlgtloeUe :Rqet= Oto[sr a eAlwdsr eus > pinUe] =gtsralwd eUe(loeFoDr)_ roavlna a oh =gtloeUe( eAlwdsr Mp a( "isNm">na" frtae-"oh, "atae-"erla, lsNm">ptel" "g">2 ae-"" ) )
  15. 15. GET REAL?Alt+Tab and code!
  16. 16. DISTRIBUTED ET AL. W/ AKKA Messages Actors Mailbox Fault-Tolerant
  17. 17. MESSAGES Sharing resource SynchronousMessage Passing Style to the rescueDont call, but send asynchronously Immutable
  18. 18. ACTORS Worker/SenderReact to message, Create message Hold a state Mutable
  19. 19. MAILBOX Queue of messagesInvoke dedicated actor when computing unit available
  20. 20. FAULT TOLERANT Actors hidden by reference Actors created hierarchicallyOnion layers of supervision => restart, stop, bubble, ...
  21. 21. CODE IN PEACEBack to the wild
  22. 22. PLAY! WITH THE WEBReactive and non-blockingAsynchronous with no pain Scala & Java End-to-end integration
  23. 23. REACTIVE AND NON-BLOCKING Using JBoss NettyReact to content using Iteratees
  24. 24. ASYNCHRONOUS WITH NO PAIN Using Promise and Future... ... easily using Continuation
  25. 25. SCALA & JAVAScala for the core and API Java API available
  26. 26. END-TO-END INTEGRATIONFrom the database to the web client Reduce runtime time exceptions... ... Increase compile time errors
  27. 27. >> PLAY NEW
  28. 28. THANKS! (FOR NOT LEAVING)chipchip: @noootsabG+: andy.petrellasocial coding: github / andypetrellaFB: RIPBlog (TBC): http://ska-la.blogspot.beCompany: NextLab Come Back! @WAJUG

×