What is the Groovy truth of an empty closure? -


i trying predict behavior of code in groovy

userlist.find { } 

.find documentation

when find method invoked , passed closure returns first element evaluates closure groovies understanding of true. when find method called without parameters returns first object in list matches true according groovy truth.

what happens if empty closure used?

  1. will evaluate true , first element of list returned?
  2. will evaluate false , after iterating on list null returned?
  3. will behave .find()?

from groovy closures formal definition (alternative source):

closures have return value. value may specified via 1 or more explicit return statement in closure body, or value of last executed statement if return not explicitly specified. if last executed statement has no value (for example, if last statement call void method), null returned.

and groovy truth

object references
non-null object references coerced true.
...

assert !null 

that suggests me truth of return value of empty closure false, find never find anything, , presumably return null.


Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -