Groovy Functional Programming - Pure Functions

Functional programming and pure functions go hand in hand. When we program in functional style, it is recommended to write pure functions as much as possible. So what are pure functions? A pure function is one which Does not produce any side effects andDoes not depend on any side effectsLet…

Groovy Functional Programming - Function (Closure) Composition

Consider the following closures. def increment = { number -> number + 1 } def square = { number -> number * number } println increment(2) // 3 println square(2) // 4 If you are not familiar with closures, this article provides the necessary details. Now suppose you want to calculate the square of a number…

Groovy Functional Programming - Currying

One of the design techniques used in functional programming is to create a generic functions and derive special functions from the generic ones by fixing some of the arguments. To understand this consider the following use-case. We want to be able to double, triple and quadruple numbers. We can write…

Groovy Functional Programming - Higher Order Functions

Lets create a closure which adds two numbers. def add = { number1, number2 -> number1 + number2 } If you are not familiar with closures, this article has the necessary details. Let's create a function which accepts this closure and invokes it by passing two numbers. def perform(def operation) { def number1…

Groovy Functional Programming - Closures

From functions to closuresConsider the following function. def greet() { println "Hello" } You can invoke the greet function in the following way greet() // prints "Hello" Unlike variables/ values, one can neither pass a function as an argument to another function nor return a function from another function. This means functions are…

Groovy: Working with Collections - Part 2

AbstractGroovy is a dynamic language on Java platform. Groovy provides extensive support for working with collection, with native support for list and map literals.In this article, I will explore the options for working with collections effectively. We will explore various collection types, internal iterators, map reduce methods, method chaining…

Groovy: Working with Collections - Part 1

AbstractGroovy is a dynamic language on Java platform. Groovy provides extensive support for working with collection, with native support for list and map literals.In this article, I will explore the options for working with collections effectively. We will explore various collection types, internal iterators, map reduce methods, method chaining…

A Taste of Groovy

AbstractJVM popularised the idea of platform independence. However Java was the only language available to the developers who wanted to take advantage of the benefits of JVM. Developer productivity on Java was a real challenge and this lead to the development of Groovy language. Groovy is a dynamic language targeted…