SlideShare a Scribd company logo
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!

More Related Content

PDF
Javaone - Getting Funky with Groovy
PDF
Functional Groovy - Confess
PDF
Notes: Verilog Part 5 - Tasks and Functions
PDF
Notes: Verilog Part 1 - Overview - Hierarchical Modeling Concepts - Basics
PDF
Notes: Verilog Part 4- Behavioural Modelling
PPTX
Java.util.concurrent.concurrent hashmap
PDF
Functional Programming for OO Programmers (part 1)
Javaone - Getting Funky with Groovy
Functional Groovy - Confess
Notes: Verilog Part 5 - Tasks and Functions
Notes: Verilog Part 1 - Overview - Hierarchical Modeling Concepts - Basics
Notes: Verilog Part 4- Behavioural Modelling
Java.util.concurrent.concurrent hashmap
Functional Programming for OO Programmers (part 1)

What's hot (20)

PDF
FregeDay: Design and Implementation of the language (Ingo Wechsung)
ODP
At Last an OCL Debugger
PPTX
Closures
ODP
Safe navigation in OCL
PDF
Notes: Verilog Part 2 - Modules and Ports - Structural Modeling (Gate-Level M...
PDF
Frege Tutorial at JavaOne 2015
PPSX
Java 8 – completion stage
ODP
OCL 2.4. (... 2.5)
PPTX
Demystifying functional effect systems in Scala
PPT
Asynchronous Programming in C# - Part 1
ODP
QVT Traceability: What does it really mean?
PPTX
Concurrency with side-effects – cats way
PDF
The JavaScript You Wished You Knew
PDF
15 anonymous methods, partial types and nullable types
PDF
Command line-arguments-in-java-tutorial
PDF
Instrumenting Go (Gopherconindia Lightning talk by Bhasker Kode)
PDF
Swift, a quick overview
KEY
Fork/Join for Fun and Profit!
PDF
FregeDay: Roadmap for resolving differences between Haskell and Frege (Ingo W...
PDF
FregeFX - JavaFX with Frege, a Haskell for the JVM
FregeDay: Design and Implementation of the language (Ingo Wechsung)
At Last an OCL Debugger
Closures
Safe navigation in OCL
Notes: Verilog Part 2 - Modules and Ports - Structural Modeling (Gate-Level M...
Frege Tutorial at JavaOne 2015
Java 8 – completion stage
OCL 2.4. (... 2.5)
Demystifying functional effect systems in Scala
Asynchronous Programming in C# - Part 1
QVT Traceability: What does it really mean?
Concurrency with side-effects – cats way
The JavaScript You Wished You Knew
15 anonymous methods, partial types and nullable types
Command line-arguments-in-java-tutorial
Instrumenting Go (Gopherconindia Lightning talk by Bhasker Kode)
Swift, a quick overview
Fork/Join for Fun and Profit!
FregeDay: Roadmap for resolving differences between Haskell and Frege (Ingo W...
FregeFX - JavaFX with Frege, a Haskell for the JVM
Ad

Viewers also liked (6)

PDF
Gr8conf Flying with Griffon
PDF
Øredev 09 - Introduction to Groovy
PDF
Groovy AST Demyistified - 33degree
PDF
A Walkthrough of Groovy AST Transformations
PPT
Eclipsecon08 Introduction To Groovy
PPTX
Java Libraries You Can’t Afford to Miss
Gr8conf Flying with Griffon
Øredev 09 - Introduction to Groovy
Groovy AST Demyistified - 33degree
A Walkthrough of Groovy AST Transformations
Eclipsecon08 Introduction To Groovy
Java Libraries You Can’t Afford to Miss
Ad

Similar to Jfokus functional groovy (20)

PDF
Functional Programming in Groovy
PDF
Learning groovy -EU workshop
PDF
Introduction to Groovy (Serbian Developer Conference 2013)
PDF
Introductionto fp with groovy
PPTX
Groovy closures
PPT
Groovy unleashed
PDF
An Introduction to Groovy for Java Developers
PDF
What's in Groovy for Functional Programming
PPT
Groovy presentation
PDF
Groovy.pptx
PPTX
Groovy Programming Language
ODP
Learning groovy 1: half day workshop
PPTX
Groovy And Grails Introduction
PDF
functional groovy
ODP
PPTX
Top 16 Groovy(Tutorial) Interview Questions - TAE
PDF
Apache Groovy: the language and the ecosystem
PDF
Discovering functional treasure in idiomatic Groovy
PDF
Groovy and Grails talk
PPTX
Groovy brownbag
Functional Programming in Groovy
Learning groovy -EU workshop
Introduction to Groovy (Serbian Developer Conference 2013)
Introductionto fp with groovy
Groovy closures
Groovy unleashed
An Introduction to Groovy for Java Developers
What's in Groovy for Functional Programming
Groovy presentation
Groovy.pptx
Groovy Programming Language
Learning groovy 1: half day workshop
Groovy And Grails Introduction
functional groovy
Top 16 Groovy(Tutorial) Interview Questions - TAE
Apache Groovy: the language and the ecosystem
Discovering functional treasure in idiomatic Groovy
Groovy and Grails talk
Groovy brownbag

More from Andres Almiray (20)

PDF
Dealing with JSON in the relational world
PDF
Deploying to production with confidence 🚀
PDF
Going beyond ORMs with JSON Relational Duality Views
PDF
Setting up data driven tests with Java tools
PDF
Creando, creciendo, y manteniendo una comunidad de codigo abierto
PDF
Liberando a produccion con confianza
PDF
Liberando a produccion con confidencia
PDF
OracleDB Ecosystem for Java Developers
PDF
Softcon.ph - Maven Puzzlers
PDF
Maven Puzzlers
PDF
Oracle Database Ecosystem for Java Developers
PDF
JReleaser - Releasing at the speed of light
PDF
Building modular applications with the Java Platform Module System and Layrry
PDF
Going Reactive with g rpc
PDF
Building modular applications with JPMS and Layrry
PDF
Taking Micronaut out for a spin
PDF
Apache Groovy's Metaprogramming Options and You
PDF
What I wish I knew about Maven years ago
PDF
What I wish I knew about maven years ago
PDF
The impact of sci fi in tech
Dealing with JSON in the relational world
Deploying to production with confidence 🚀
Going beyond ORMs with JSON Relational Duality Views
Setting up data driven tests with Java tools
Creando, creciendo, y manteniendo una comunidad de codigo abierto
Liberando a produccion con confianza
Liberando a produccion con confidencia
OracleDB Ecosystem for Java Developers
Softcon.ph - Maven Puzzlers
Maven Puzzlers
Oracle Database Ecosystem for Java Developers
JReleaser - Releasing at the speed of light
Building modular applications with the Java Platform Module System and Layrry
Going Reactive with g rpc
Building modular applications with JPMS and Layrry
Taking Micronaut out for a spin
Apache Groovy's Metaprogramming Options and You
What I wish I knew about Maven years ago
What I wish I knew about maven years ago
The impact of sci fi in tech

Jfokus functional groovy