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

前端 未结 6 2103
难免孤独
难免孤独 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:26

    I think you're working on the wrong level of abstraction. The .each block does exactly what it says: it executes the closure once for each element. What you probably want instead is to use List.indexOf to find the right specificElement, and then do the work you need to do on it.

提交回复
热议问题