blog rss feed

findAll path in Groovy.

Author: Dave Cherry last modified
Keywords: groovy programming

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"})

Please leave a comment



Search

Blog calendar

blog: previous month September 2010 blog: next month
su mo tu we th fr sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30