Page 1 of 1

[Question] What is the meaning of "it" inside "any" closure?

Posted: 15 Oct 2024, 13:47
by Abu3safeer
Hello, I read this viewtopic.php?t=12369
in the example

Code: Select all

{languages.any{ audioLanguages =~ it } ? "[Original Language]" : "[Dubbed]"}
What is the meaning of "it", also what does "=~" mean?

Re: [Question] What is the meaning of "it" inside "any" closure?

Posted: 15 Oct 2024, 16:18
by rednoah
:idea: it is the parameter that is passed as argument to the closure: Groovy Language Documentation › Implicit parameter

:idea: =~ is the regex-find operator: Groovy Language Documentation › Find operator



tl;dr this is short:

Groovy: Select all

languages.any{ audioLanguages =~ it }
for this:

Groovy: Select all

languages.any{ language -> java.util.regex.Pattern.compile(language.toString()).matcher(audioLanguages.toString()).find()  }