Is it possible to break out of closure in groovy

groovy

is there a way to 'break' out of a groovy closure.

maybe something like this:

[1, 2, 3].each { 
  println(it)
  if (it == 2)
    break 
}

Best Answer

I often forget that Groovy implements an "any" method.

[1, 2, 3].any
{   
   println it
   return (it == 2)
}​