• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Ff to-fp

Ff to-fp



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

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



Total Views
Views on SlideShare
Embed Views



3 Embeds 48

https://twitter.com 35
http://www.linkedin.com 11
https://www.linkedin.com 2



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    Ff to-fp Ff to-fp Presentation Transcript

    • FP USING SCALA What is FP? Scala =?= FP In action...
    • 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
    • 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
    • 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 )
    • 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
    • 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: 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)
    • 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
    • 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
    • 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 } } }}
    • 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-"" ) )
    • 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 asynchronously Immutable
    • 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 => restart, stop, bubble, ...
    • 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 errors
    • >> PLAY NEW
    • THANKS! (FOR NOT LEAVING)chipchip: @noootsabG+: andy.petrellasocial coding: github / andypetrellaFB: RIPBlog (TBC): http://ska-la.blogspot.beCompany: NextLab Come Back! @WAJUG