Jfokus functional groovy

Andres Almiray
Andres AlmiraySoftware Developer, Open Source advocate
FUNCTIONAL
GROOVY
ANDRES ALMIRAY
CANOO ENGINEERING A.G.
@AALMIRAY
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
Jfokus functional groovy
FUNCTIONAL
GROOVY,
ARE YOU
KIDDING ME?
GROOVY IS NOT
HASKELL
     RUSSEL WINDER
CLOSURES == FUNCTIONS
Closures are functions (i.e, blocks of code) with an
environment containing a binding for all free variables of the
function
CLOSURES == FUNCTIONS
Closures are NOT side effect free by design
CLOSURES: PARAMETERS (1)
Parameter types may be omitted if type information is not
needed
CLOSURES: PARAMETERS (2)
Parameters may have default values




NOTE: Default values must be defined from right to left
CLOSURES: DEFAULT
PARAMETER
Closures may have a default parameter named it
CLOSURES LEAD TO …
Partial Evaluation
Composition
Memoization
Tail calls
Iterators
Streams
PARTIAL EVALUATION (1)
Currying creates a new closure with fixed parameters, left to
right
PARTIAL EVALUATION (2)
Currying may be applied right to left too, even on an arbitrary
index
COMPOSITION (1)
Closures may be composed (left to right) using the >>
operator
COMPOSITION (2)
Closures may be composed (right to left) using the <<
operator
MEMOIZATION
Cache computed values for increased performance
TAIL CALLS (1)
Recursive closures may use Tail Calls thanks to trampoline()
TAIL CALLS (2)
Apply @TailRecursive on methods




https://github.com/jlink/tailrec/
ITERATORS (1)
ITERATORS (2)
p
ITERATORS
OBJECTS AS PARTIAL EVALS
Any class may implement the call() method, enabling implicit
evaluation
METHODS AS CLOSURES
Any method may be transformed to a Closure using the .&
operator
STREAMS (1)
Lazy generators. Extension module created by @tim_yates




http://timyates.github.com/groovy-stream/
STREAMS (2)
Groovy is Java friendly. Usa any Java library such as
functional-java
IMMUTABILITY
The @Immutable AST transformation makes writing
immutable classes trivial
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
PARALLEL COLLECTIONS
Gpars enhances JDK/GDK collections with parallel execution
enabled versions
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
Q&A
THANK
YOU!
1 of 31

More Related Content

Viewers also liked(6)

Gr8conf Flying with GriffonGr8conf Flying with Griffon
Gr8conf Flying with Griffon
Andres Almiray589 views
Øredev 09 - Introduction to GroovyØredev 09 - Introduction to Groovy
Øredev 09 - Introduction to Groovy
Andres Almiray471 views
Groovy AST Demyistified - 33degreeGroovy AST Demyistified - 33degree
Groovy AST Demyistified - 33degree
Andres Almiray1.4K views
Eclipsecon08 Introduction To GroovyEclipsecon08 Introduction To Groovy
Eclipsecon08 Introduction To Groovy
Andres Almiray1.2K views

Similar to Jfokus functional groovy(20)

The GO Language : From Beginners to GophersThe GO Language : From Beginners to Gophers
The GO Language : From Beginners to Gophers
Alessandro Sanino384 views
Java 9 featuresJava 9 features
Java 9 features
shrinath97121 views
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
ciklum_ods640 views
Designing Better APIDesigning Better API
Designing Better API
Kaniska Mandal472 views
Ruby Presentation Ruby Presentation
Ruby Presentation
platico_dev6.2K views
G parsG pars
G pars
NexThoughts Technologies541 views
Understanding And Using ReflectionUnderstanding And Using Reflection
Understanding And Using Reflection
Ganesh Samarthyam640 views
Andy On ClosuresAndy On Closures
Andy On Closures
melbournepatterns1.2K views
Native Java with GraalVMNative Java with GraalVM
Native Java with GraalVM
Sylvain Wallez1K views
AnnotationsAnnotations
Annotations
Knoldus Inc.8.8K views
Whoops! Where did my architecture go?Whoops! Where did my architecture go?
Whoops! Where did my architecture go?
Oliver Gierke7.1K views
Java for MainframersJava for Mainframers
Java for Mainframers
Rich Helton1.4K views
What's New in Groovy 1.6?What's New in Groovy 1.6?
What's New in Groovy 1.6?
Guillaume Laforge697 views
JavascriptJavascript
Javascript
Sheldon Abraham336 views

More from Andres Almiray(20)

Softcon.ph - Maven PuzzlersSoftcon.ph - Maven Puzzlers
Softcon.ph - Maven Puzzlers
Andres Almiray5 views
Maven PuzzlersMaven Puzzlers
Maven Puzzlers
Andres Almiray49 views
Going Reactive with g rpcGoing Reactive with g rpc
Going Reactive with g rpc
Andres Almiray142 views
Taking Micronaut out for a spinTaking Micronaut out for a spin
Taking Micronaut out for a spin
Andres Almiray644 views
The impact of sci fi in techThe impact of sci fi in tech
The impact of sci fi in tech
Andres Almiray210 views
Gradle Ex Machina - Devoxx 2019Gradle Ex Machina - Devoxx 2019
Gradle Ex Machina - Devoxx 2019
Andres Almiray490 views
Creating Better Builds with GradleCreating Better Builds with Gradle
Creating Better Builds with Gradle
Andres Almiray239 views
Gradle ex-machinaGradle ex-machina
Gradle ex-machina
Andres Almiray557 views
Go Java, Go!Go Java, Go!
Go Java, Go!
Andres Almiray866 views
Going Reactive with gRPCGoing Reactive with gRPC
Going Reactive with gRPC
Andres Almiray2.4K views
The JavaFX EcosystemThe JavaFX Ecosystem
The JavaFX Ecosystem
Andres Almiray933 views

Jfokus functional groovy