I want to know if all (or none) of the items of a Collection in Groovy satisfy certain condition.
I know that in ruby (and in c# with linq), you can call methods like all?
and none?
and pass the condition as a closure to accomplish this.
Is there an equivalent for this methods in Groovy?
Yes, its !any
(for Ruby's none
) and every
(for Ruby's all
):
def list = [1, 2]
assert !list.any { it < 0 }
assert list.every { it > 0 }
See also documentation at http://groovy.codehaus.org/JN1015-Collections
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With