In functional programming, we have the concept of an identity function. An identity function returns the same result as the input of the function. Groovy has a lot of functional paradigms, including an identity function. Of course, in Groovy's case, it is an identity closure. It is defined as a constant in the Closure class: Closure.IDENTITY. If we use this closure, we get the same result as the argument we provide.

In the following example, we first create our own identity closure. Next, we use the built-in Closure.IDENTITY closure: