jfokus functional groovy
DESCRIPTION
TRANSCRIPT
![Page 1: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/1.jpg)
FUNCTIONAL GROOVY ANDRES ALMIRAY CANOO ENGINEERING A.G. @AALMIRAY
![Page 2: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/2.jpg)
ABOUT THE SPEAKER Java developer since the beginning True believer in open source Groovy committer since 2007
Project lead of the Griffon framework
Currently working for
![Page 3: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/3.jpg)
![Page 4: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/4.jpg)
FUNCTIONAL GROOVY, ARE YOU KIDDING ME?
![Page 5: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/5.jpg)
GROOVY IS NOT HASKELL RUSSEL WINDER
![Page 6: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/6.jpg)
CLOSURES == FUNCTIONS Closures are functions (i.e, blocks of code) with an environment containing a binding for all free variables of the function
![Page 7: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/7.jpg)
CLOSURES == FUNCTIONS Closures are NOT side effect free by design
![Page 8: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/8.jpg)
CLOSURES: PARAMETERS (1) Parameter types may be omitted if type information is not needed
![Page 9: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/9.jpg)
CLOSURES: PARAMETERS (2) Parameters may have default values NOTE: Default values must be defined from right to left
![Page 10: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/10.jpg)
CLOSURES: DEFAULT PARAMETER Closures may have a default parameter named it
![Page 11: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/11.jpg)
CLOSURES LEAD TO … Partial Evaluation Composition Memoization Tail calls Iterators Streams
![Page 12: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/12.jpg)
PARTIAL EVALUATION (1) Currying creates a new closure with fixed parameters, left to right
![Page 13: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/13.jpg)
PARTIAL EVALUATION (2) Currying may be applied right to left too, even on an arbitrary index
![Page 14: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/14.jpg)
COMPOSITION (1) Closures may be composed (left to right) using the >> operator
![Page 15: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/15.jpg)
COMPOSITION (2) Closures may be composed (right to left) using the << operator
![Page 16: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/16.jpg)
MEMOIZATION Cache computed values for increased performance
![Page 17: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/17.jpg)
TAIL CALLS (1) Recursive closures may use Tail Calls thanks to trampoline()
![Page 18: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/18.jpg)
TAIL CALLS (2) Apply @TailRecursive on methods
https://github.com/jlink/tailrec/
![Page 19: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/19.jpg)
ITERATORS (1)
![Page 20: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/20.jpg)
ITERATORS (2) p
![Page 21: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/21.jpg)
ITERATORS
![Page 22: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/22.jpg)
OBJECTS AS PARTIAL EVALS Any class may implement the call() method, enabling implicit evaluation
![Page 23: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/23.jpg)
METHODS AS CLOSURES Any method may be transformed to a Closure using the .& operator
![Page 24: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/24.jpg)
STREAMS (1) Lazy generators. Extension module created by @tim_yates
http://timyates.github.com/groovy-stream/
![Page 25: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/25.jpg)
STREAMS (2) Groovy is Java friendly. Usa any Java library such as functional-java
![Page 26: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/26.jpg)
IMMUTABILITY The @Immutable AST transformation makes writing immutable classes trivial
![Page 27: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/27.jpg)
GPARS http://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
![Page 28: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/28.jpg)
PARALLEL COLLECTIONS Gpars enhances JDK/GDK collections with parallel execution enabled versions
![Page 29: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/29.jpg)
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
![Page 30: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/30.jpg)
Q & A
![Page 31: Jfokus functional groovy](https://reader034.vdocuments.mx/reader034/viewer/2022042606/54868dd1b4af9f910d8b5176/html5/thumbnails/31.jpg)
THANK YOU!