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

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
Abu3safeer
Posts: 2
Joined: 15 Oct 2024, 13:37

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

Post 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?
User avatar
rednoah
The Source
Posts: 23513
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

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

Post 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()  }
:idea: Please read the FAQ and How to Request Help.
Post Reply