SlideShare a Scribd company logo
GETTING 
FUNKY 
WITH 
ANDRES ALMIRAY IX-CHEL RUIZ 
@AALMIRAY @IXCHELRUIZ
Javaone - Getting Funky with Groovy
Javaone - Getting Funky with Groovy
Javaone - Getting Funky with Groovy
FUNCTIONAL 
GROOVY, 
ARE YOU 
KIDDING ME?
GROOVY IS NOT 
HASKELL 
RUSSEL WINDER 
* have a look at https://github.com/frege/frege
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 
 
Iterators 
Streams 
Partial Evaluation 
Composition 
Memoization 
Tail calls
ITERATORS (1)
ITERATORS (2) 
p
ITERATORS
GEEKS & BEERS 
Mattias Johan 
Functional Java 
Lambdaj 
Google Guava
USE CASES 
Given 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
USE CASE 1 
Find the cheapest beer
USE CASE 2 
Find the most expensive beer
USE CASE 3 
What’s the name of the most expensive beer
USE CASE 4 
Get all the beer names
USE CASE 5 
What’s the total price
PROS & CONS 
Java collections 
Closures! 
Plays nice with all 
other functional 
frameworks 
Metaprogramming! 
Non-lazy evaluation 
Streams not 
included in core 
filter/map/reduce
S/COLLECT/MAP/ 
Don’t like collect? Use Groovy’s metaprogramming
STREAMS (1) 
Lazy generators. Extension module created by @tim_yates 
http://timyates.github.com/groovy-stream/
STREAMS (2) 
Groovy is Java friendly. Use any Java library such as 
functional-java
FJ MODULE EXTENSION 
https://github.com/mperry/functionalgroovy 
Update: Mark has posted some notes at 
http://mperry.github.io/2013/07/28/groovy-null-handling.html
STREAMS (JDK8) 
Collection and Lambda friendly, lazy evaluation
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
OBJECTS AS PARTIAL EVALS 
Any class may implement the call() method, enabling implicit 
evaluation
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/ 
now included in Groovy 2.3!
METHODS AS CLOSURES 
Any method may be transformed to a Closure using the .& 
operator
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
MONADS 
https://github.com/dsrkoc/monadologie
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
THANK YOU! 
HTTP://PEOPLE.CANOO.COM/SHARE 
Andres Almiray Ix-chel Ruiz 
@aalmiray @ixchelruiz

More Related Content

PDF
Jfokus functional groovy
KEY
Fitc 2012 - rise of the modules
PPT
Print Testing
PDF
PDF
Android antipatterns
PPT
Log4cpp - Updated - to verify modify updates
PPTX
Golang basics for Java developers - Part 1
PDF
Version Control with Git
Jfokus functional groovy
Fitc 2012 - rise of the modules
Print Testing
Android antipatterns
Log4cpp - Updated - to verify modify updates
Golang basics for Java developers - Part 1
Version Control with Git

What's hot (11)

PPTX
A Brief Conceptual Introduction to Functional Java 8 and its API
PDF
Reactive programming with tracker
PDF
Groovy AST Demystified
PDF
PuppetConf 2014 Killer R10K Workflow Without Notes
PPTX
Kotlin For Android - Constructors and Control Flow (part 2 of 7)
PPTX
C compilation process
PDF
Command Line Arguments with Getopt::Long
PDF
Golang
PDF
Parallel program design
PDF
kikstart journey of Golang with Hello world - Gopherlabs
PPTX
Kotlin For Android - Basics (part 1 of 7)
A Brief Conceptual Introduction to Functional Java 8 and its API
Reactive programming with tracker
Groovy AST Demystified
PuppetConf 2014 Killer R10K Workflow Without Notes
Kotlin For Android - Constructors and Control Flow (part 2 of 7)
C compilation process
Command Line Arguments with Getopt::Long
Golang
Parallel program design
kikstart journey of Golang with Hello world - Gopherlabs
Kotlin For Android - Basics (part 1 of 7)
Ad

Similar to Javaone - Getting Funky with Groovy (20)

PDF
Functional Groovy - Confess
PPTX
Go Is Your Next Language — Sergii Shapoval
PDF
Greach 2014 - Metaprogramming with groovy
PDF
"Xapi-lang For declarative code generation" By James Nelson
PDF
Gradle in 45min - JBCN2-16 version
PPTX
The GO Language : From Beginners to Gophers
PPTX
OpenDaylight Developer Experience 2.0
PDF
Directive-based approach to Heterogeneous Computing
PPTX
Porting the Source Engine to Linux: Valve's Lessons Learned
PDF
Ruby Presentation
PPT
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
PPT
What's New in Groovy 1.6?
PDF
25 must know python for Interview by Tutort Academy
PDF
PHP Development Tools
PPTX
Unit-3.pptx node js ppt documents semester-5
KEY
Eclipse meets e4
PDF
Alive and Well with Java 8
PDF
Go. why it goes v2
PDF
Rust and Eclipse
PPTX
Go. Why it goes
Functional Groovy - Confess
Go Is Your Next Language — Sergii Shapoval
Greach 2014 - Metaprogramming with groovy
"Xapi-lang For declarative code generation" By James Nelson
Gradle in 45min - JBCN2-16 version
The GO Language : From Beginners to Gophers
OpenDaylight Developer Experience 2.0
Directive-based approach to Heterogeneous Computing
Porting the Source Engine to Linux: Valve's Lessons Learned
Ruby Presentation
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
What's New in Groovy 1.6?
25 must know python for Interview by Tutort Academy
PHP Development Tools
Unit-3.pptx node js ppt documents semester-5
Eclipse meets e4
Alive and Well with Java 8
Go. why it goes v2
Rust and Eclipse
Go. Why it goes
Ad

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

Recently uploaded (20)

PPTX
CHAPTER 2 - PM Management and IT Context
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPT
Introduction Database Management System for Course Database
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
L1 - Introduction to python Backend.pptx
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Nekopoi APK 2025 free lastest update
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Introduction to Artificial Intelligence
PPTX
Online Work Permit System for Fast Permit Processing
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Digital Strategies for Manufacturing Companies
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
ai tools demonstartion for schools and inter college
PDF
Understanding Forklifts - TECH EHS Solution
CHAPTER 2 - PM Management and IT Context
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Introduction Database Management System for Course Database
Design an Analysis of Algorithms II-SECS-1021-03
L1 - Introduction to python Backend.pptx
Wondershare Filmora 15 Crack With Activation Key [2025
Nekopoi APK 2025 free lastest update
Operating system designcfffgfgggggggvggggggggg
PTS Company Brochure 2025 (1).pdf.......
Introduction to Artificial Intelligence
Online Work Permit System for Fast Permit Processing
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Upgrade and Innovation Strategies for SAP ERP Customers
Digital Strategies for Manufacturing Companies
Navsoft: AI-Powered Business Solutions & Custom Software Development
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
How to Migrate SBCGlobal Email to Yahoo Easily
ai tools demonstartion for schools and inter college
Understanding Forklifts - TECH EHS Solution

Javaone - Getting Funky with Groovy