Functional Groovy - Confess
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Functional Groovy - Confess

le

  • 1,871 vues

Functional Groovy - Confess

Functional Groovy - Confess

Statistiques

Vues

Total des vues
1,871
Vues sur SlideShare
1,829
Vues externes
42

Actions

J'aime
7
Téléchargements
30
Commentaires
0

1 intégré 42

https://twitter.com 42

Accessibilité

Catégories

Détails de l'import

Uploaded via as Adobe PDF

Droits d'utilisation

CC Attribution-NonCommercial LicenseCC Attribution-NonCommercial License

Report content

Signalé comme inapproprié Signaler comme inapproprié
Signaler comme inapproprié

Indiquez la raison pour laquelle vous avez signalé cette présentation comme n'étant pas appropriée.

Annuler
  • Full Name Full Name Comment goes here.
    Êtes-vous sûr de vouloir
    Votre message apparaîtra ici
    Processing...
Poster un commentaire
Modifier votre commentaire

Functional Groovy - Confess Presentation Transcript

  • 1. FUNCTIONAL GROOVY ANDRES ALMIRAY ANDRES.ALMIRAY@CANOO.COM @AALMIRAY
  • 2. ABOUT THE SPEAKERJava developer since the beginningTrue believer in open sourceGroovy committer since 2007Project lead of the Griffon frameworkCurrently working for
  • 3. FUNCTIONALGROOVY,ARE YOUKIDDING ME?
  • 4. GROOVY IS NOTHASKELL RUSSEL WINDER
  • 5. CLOSURES == FUNCTIONSClosures are functions (i.e, blocks of code) with anenvironment containing a binding for all free variables of thefunction
  • 6. CLOSURES == FUNCTIONSClosures are NOT side effect free by design
  • 7. CLOSURES: PARAMETERS (1)Parameter types may be omitted if type information is notneeded
  • 8. CLOSURES: PARAMETERS (2)Parameters may have default valuesNOTE: Default values must be defined from right to left
  • 9. CLOSURES: DEFAULTPARAMETERClosures may have a default parameter named it
  • 10. CLOSURES LEAD TO …IteratorsStreamsPartial EvaluationCompositionMemoizationTail calls
  • 11. ITERATORS (1)
  • 12. ITERATORS (2)p
  • 13. ITERATORS
  • 14. GEEKS & BEERS Functional Java Lambdaj Google Guava
  • 15. USE CASESGiven a list of beers and their prices: Find the cheapest beer Find the most expensive beer What’s the name of the most expensive beer Get all the beer names What’s the total price
  • 16. USE CASE 1Find the cheapest beer
  • 17. USE CASE 2Find the most expensive beer
  • 18. USE CASE 3What’s the name of the most expensive beer
  • 19. USE CASE 4Get all the beer names
  • 20. USE CASE 5What’s the total price
  • 21. PROS & CONSJava collections Non-lazy evaluationClosures! Streams notPlays nice with all included in coreother functional filter/map/reduceframeworksMetaprogramming!
  • 22. S/COLLECT/MAP/Don’t like collect? Use Groovy’s metaprogramming
  • 23. STREAMS (1)Lazy generators. Extension module created by @tim_yateshttp://timyates.github.com/groovy-stream/
  • 24. STREAMS (2)Groovy is Java friendly. Use any Java library such asfunctional-java
  • 25. FJ MODULE EXTENSIONhttps://github.com/mperry/functionalgroovy
  • 26. STREAMS (JDK8)Collection and Lambda friendly, lazy evaluation
  • 27. STREAMS (JDK8)https://twitter.com/jodastephen/status/316991150672183297
  • 28. PARTIAL EVALUATION (1)Currying creates a new closure with fixed parameters, left toright
  • 29. PARTIAL EVALUATION (2)Currying may be applied right to left too, even on an arbitraryindex
  • 30. OBJECTS AS PARTIAL EVALSAny class may implement the call() method, enabling implicitevaluation
  • 31. COMPOSITION (1)Closures may be composed (left to right) using the >>operator
  • 32. COMPOSITION (2)Closures may be composed (right to left) using the <<operator
  • 33. MEMOIZATIONCache computed values for increased performance
  • 34. TAIL CALLS (1)Recursive closures may use Tail Calls thanks to trampoline()
  • 35. TAIL CALLS (2)Apply @TailRecursive on methodshttps://github.com/jlink/tailrec/
  • 36. METHODS AS CLOSURESAny method may be transformed to a Closure using the .&operator
  • 37. IMMUTABILITYThe @Immutable AST transformation makes writingimmutable classes trivial
  • 38. GPARShttp://gpars.codehaus.org/ Concurrent collection processing Composable asynchronous functions Fork/Join abstraction Actor programming model Dataflow concurrency constructs CSP Agent - an thread-safe reference to mutable state
  • 39. PARALLEL COLLECTIONSGpars enhances JDK/GDK collections with parallel executionenabled versions
  • 40. MONADShttps://github.com/dsrkoc/monadologie
  • 41. RESOURCES•  http://pragprog.com/magazines/2013-01/using- memoization-in-groovy•  http://www.ibm.com/developerworks/views/java/ libraryview.jsp?search_by=functional+thinking•  https://github.com/jlink/tailrec/•  http://timyates.github.com/groovy-stream•  http://www.jroller.com/vaclav•  http://gpars.codehaus.org•  http://www.slideshare.net/arturoherrero/functional- programming-with-groovy
  • 42. HTTP://PEOPLE.CANOO.COM/SHARE ANDRES ALMIRAY ANDRES.ALMIRAY@CANOO.COM @AALMIRAY