Jfokus functional groovy

2,025 views

Published on

Jfokus functional groovy

  1. 1. FUNCTIONALGROOVYANDRES ALMIRAYCANOO ENGINEERING A.G.@AALMIRAY
  2. 2. ABOUT THE SPEAKERJava developer since the beginningTrue believer in open sourceGroovy committer since 2007Project lead of the Griffon frameworkCurrently working for
  3. 3. FUNCTIONALGROOVY,ARE YOUKIDDING ME?
  4. 4. GROOVY IS NOTHASKELL RUSSEL WINDER
  5. 5. CLOSURES == FUNCTIONSClosures are functions (i.e, blocks of code) with anenvironment containing a binding for all free variables of thefunction
  6. 6. CLOSURES == FUNCTIONSClosures are NOT side effect free by design
  7. 7. CLOSURES: PARAMETERS (1)Parameter types may be omitted if type information is notneeded
  8. 8. CLOSURES: PARAMETERS (2)Parameters may have default valuesNOTE: Default values must be defined from right to left
  9. 9. CLOSURES: DEFAULTPARAMETERClosures may have a default parameter named it
  10. 10. CLOSURES LEAD TO …Partial EvaluationCompositionMemoizationTail callsIteratorsStreams
  11. 11. PARTIAL EVALUATION (1)Currying creates a new closure with fixed parameters, left toright
  12. 12. PARTIAL EVALUATION (2)Currying may be applied right to left too, even on an arbitraryindex
  13. 13. COMPOSITION (1)Closures may be composed (left to right) using the >>operator
  14. 14. COMPOSITION (2)Closures may be composed (right to left) using the <<operator
  15. 15. MEMOIZATIONCache computed values for increased performance
  16. 16. TAIL CALLS (1)Recursive closures may use Tail Calls thanks to trampoline()
  17. 17. TAIL CALLS (2)Apply @TailRecursive on methodshttps://github.com/jlink/tailrec/
  18. 18. ITERATORS (1)
  19. 19. ITERATORS (2)p
  20. 20. ITERATORS
  21. 21. OBJECTS AS PARTIAL EVALSAny class may implement the call() method, enabling implicitevaluation
  22. 22. METHODS AS CLOSURESAny method may be transformed to a Closure using the .&operator
  23. 23. STREAMS (1)Lazy generators. Extension module created by @tim_yateshttp://timyates.github.com/groovy-stream/
  24. 24. STREAMS (2)Groovy is Java friendly. Usa any Java library such asfunctional-java
  25. 25. IMMUTABILITYThe @Immutable AST transformation makes writingimmutable classes trivial
  26. 26. 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
  27. 27. PARALLEL COLLECTIONSGpars enhances JDK/GDK collections with parallel executionenabled versions
  28. 28. 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
  29. 29. Q&A
  30. 30. THANKYOU!

×