How to select specific field using Groovy Closure
===

Given:

    class FruitBasket {
        int apples = 0
        int oranges = 0
    }

I need to pick out apples from each FruitBasket. The work need to be done in processFruit:

    def processFruit(list, picker) {
        list.each {
            println "processing " + picker(it)
        }
    }
    
    def processAll() {
        List fruitList = [
            new FruitBasket("apples": 2, "oranges": 4),
            new FruitBasket("apples": 3, "oranges": 5)
        ]
        
        processFruit(fruitList, applePicker)
    }
    
    def applePicker(FruitBasket f) {
        return f.getApples()    
    }

but it is complaining @ runtime that

    No such property: applePicker for class: FooTest

possibly a problem with the closures FruitBasket arg...