Support Questions

Find answers, ask questions, and share your expertise

Nifi: Groovy doesn't accept lambdas?

avatar
Contributor

I want to know if nifi 1.3.0 version contains groovy version in which i can use lambdas?.

1 ACCEPTED SOLUTION

avatar
Master Guru

IIRC, Groovy 3 is supposed to support the Java lambda syntax, but NiFi uses Groovy 2 which does not support it. However Groovy has always had Closures, which are very similar and used for the same purpose, so despite a small difference in syntax, you should be able to use Groovy closures the same as you would use Java lambdas. If you are referring to the Java Streams API (things like foreach() that take a lambda), Groovy has iterative and aggregate functions for that too, such as each() and eachWithIndex(), spread-dot and collect(), etc.

View solution in original post

1 REPLY 1

avatar
Master Guru

IIRC, Groovy 3 is supposed to support the Java lambda syntax, but NiFi uses Groovy 2 which does not support it. However Groovy has always had Closures, which are very similar and used for the same purpose, so despite a small difference in syntax, you should be able to use Groovy closures the same as you would use Java lambdas. If you are referring to the Java Streams API (things like foreach() that take a lambda), Groovy has iterative and aggregate functions for that too, such as each() and eachWithIndex(), spread-dot and collect(), etc.