Groovy Cookbook

Most popular posts

Groovy Regular Expressions - The Definitive Guide (Part 1)

Welcome to "Groovy Regular Expressions - The Definitive Guide"! In the next 15 minutes, you are going to learn everything you need to start working productively with regular expressions in Groovy programming language. Let’s get started!

Tail-recursive methods in Groovy

Most of the object-oriented programmers prefer constructing algorithms using imperative style over using recursion. This is pretty obvious in the JVM ecosystem, where imperative iteration is much more efficient than recursive function call chain. However, what if I tell you that in Groovy you can take advantage of clean tail-recursive functions without sacrificing performance? Interested? Let’s deep dive into it.

GraalVM and Groovy - how to start?

GraalVM became one of the most popular topics in the JVM ecosystem. It promises the highest possible speed of running JVM-based programs (when compiled to native images), hand in hand with the smaller memory footprint. It sounds interesting enough to give it a try. And today we are going to play around a little bit with running simple Groovy program after compiling to a standalone native image.

Watch my YouTube videos

15:51
26:07
23:01

Latest blog posts

How to merge two maps in Groovy?

One of the most popular map-related operation in any programming language is merging two (or more) maps. In this short blog post, I explain how to do it in the Groovy programming language, starting from the simplest + operation, up to more advanced use cases of merging nested maps and using runtime metaprogramming to add a merge method to the Map interface. Enjoy reading and learning!

Groovy dynamic Maps, generic type erasure, and raw types - an interesting use case to learn from

Dynamic type inference in Groovy might be tricky. Add generic type erasure to it, and you can find yourself in trouble. In this blog post, I would like to show you such use case and explain what happens under the hood. Enjoy reading!

Groovy 3 @NullCheck annotation - less code and less NPE

Groovy 3 helps you write less, but more secure code. Today I want to show you one of the features added in the latest release - @NullCheck annotation.

Groovy 3 String GDK improvements - takeRight, takeBetween, and a few others

Groovy 3 was released a few days ago[1], and it introduced a lot of important new features to the language. Today I want to show you a few useful improvements in the GDK. We will take a closer look into methods like takeRight, takeAfter, takeBetween, and a few others that were added to the java.lang.String class.

Three Groovy String methods that will make your life Groovier!

Groovy String API offers many useful methods to make working with strings much more pleasant. Today I would like to show you three, not so very popular, yet convenient methods. Let’s jump straight into it!

Quicksort in Groovy - can it be as fast as implemented in Java?

I started reading "Cracking the Coding Interview, 6th Edition" book recently and it inspired me to experiment a bit. It’s been a while since I implemented the quicksort algorithm the last time, and I did that in Haskell. I remember some old and imperative implementations in Java, but I never tried to implement it in Groovy. Let’s give it a try!

Groovy Trampoline Closure - a step into recursive closures

A few weeks ago an interesting question was asked on the StackOverflow. Someone experimented with a recursion in Groovy and stepped into Closure.trampoline() [1]. It quickly turned out that using TrampolineClosure makes a recursive execution slower. Is this a valid behavior, or do we do something wrong?

Spock random order of tests - how to?

Spock Framework executes test methods (features) in a single class (specification) in the declaration order. There is nothing wrong in this default behavior - we should write tests with their isolation in mind. However, in some cases, we would like to randomize test methods execution. Today we are going to learn how to do it.

Groovy Regular Expressions - The Benchmark (Part 2)

In the second part of the "Groovy Regular Expression" blog post, I want to show you some benchmarks. And let me make one thing clear - the following results you are going to see are not scientific proof. I present those results only to give you a hint about the overall performance of some cool features you have seen before.