What is the Groovy truth of an empty closure? -
i trying predict behavior of code in groovy
userlist.find { }
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?
- will evaluate true , first element of list returned?
- will evaluate false , after iterating on list
null
returned? - 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
Post a Comment