Collections

Iterators and Enumerations

Iterators and Enumerations with no further elements are coerced to false.

Code Block

assert ![].iterator() // false because the Iterator is empty
assert [0].iterator() // true because the Iterator has a next element
def v = new Vector()
assert !v.elements() // false because the Enumeration is empty
v.add(new Object())
assert v.elements() // true because the Enumeration has more elements

Maps

Non-empty maps are coerced to true.

Code Block

assert ['one':1]
assert ![:]

Matchers

Matching regex patterns are coerced to true.

Code Block

assert ('Hello World' =~ /World/) //true because matcher has at least one match