How does one return from a groovy closure and stop its execution?

前端 未结 6 2108
难免孤独
难免孤独 2020-12-30 19:22

I would like to return from a closure, like one would if using a break statement in a loop.

For example:

largeListOfElements.each{ element->
             


        
6条回答
  •  旧巷少年郎
    2020-12-30 20:01

    Today I faced a similar problem while working with each closure. I wanted to break the flow of execution based on my condition but couldn't do it.

    The easiest way to do in groovy is to use any() on a list instead of each if you wish to return a boolean based on some condition.

提交回复
热议问题