I’m sure many people who read this will already be familar with findAll, However, its something I had not fully switched on to until recently in Groovy. Since getting used to it, I’ve found more and more useful cases for it.
Where ever there is a loop iterating a collection acting as a filter, I’ve found that the findAll pattern works particularly well. For the un-initiated findAll works by iterating over the collection, and calling a closure for each entry; the closure should return true if the entry matches, otherwise false. Any items that match are added to the returned collection.
assert(["joe"] == ["joe", "dave", "bob"].findAll {it == "joe"})