|
|
|
I guess I was thinking about the shortened form to augment Groovy's GPath notation. E.g., considering GROOVY-2387, we removed a layer of magical unwrapping, so now the example is longer to type. In that example, the last line would go from:
assert [5 * 1499, 499, 4 * 499] == invoices.items.collect{ it*.total() }.flatten()
to: assert [5 * 1499, 499, 4 * 499] == invoices.items**.total().flatten()
which would look nicer. But if people think it is confusing or if it turms out too hard to implement, then the longer form is also a possibility. Perhaps a Collection.collectAll{ closure } or as per your suggestion. The double star is interesting, a method is easier to implement and doesn't require IDE developers to catch up
I'm not really sold on either of these approaches. I'd be happy to have some more feedback from others as well. What about just a collectAll method for now?
We could always add the ** later if we find it truly useful: def animalLists= [["ant", "mouse", "elephant"], ["deer", "monkey"]] assert animalLists*.size() == [3, 2] assert animalLists.collect{ it.size() } == [3, 2] assert animalLists.collectAll{ it.size() } == [[3, 5, 8], [4, 6]] // assert animalLists**.size() == [[3, 5, 8], [4, 6]] // potential future enhancement |
||||||||||||||||||||||||||||||||||||||||||||
Do you think it should be a new notation, or in this case, wouldn't a method taking a closure be enough?
Say, something like collection.recurse { it.method() }