Groovy Cookbook

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.

Read more →

Programming tips

Count frequency of a digit in a factorial of number using Haskell

Some time ago I was interviewed to one of the Java-based projects and I was asked to solve this pretty interesting puzzle. The question was "how to count frequency of a digit in a factorial of number, let’s say 1000". I tried to solve it using Java 8 Stream API, but I guess you see how bad decision it was. Problems like that can be easily solved with pure functional languages and today we are going to find out how to solve this puzzle with Haskell.

Read more →