hi,
after programmed Groovy for a while, I've got a wish list for syntax/API improvement.
- find() (or findAll()) to take a "limit" integer to decide how many records shall be returned.
e.g. [1,2,3,4].find(2){it>1} == [2,3]
- support !in or not in
e.g. 3 !in [2,3,4] == false
Remarks: we have to use !(3 in [2,3,4]) now, !3 in [2,3,4] doesn't work.
- support << to put data to map.
e.g. ([key1:"value1"] << [key2:"value2"]) == [key1:"value1",key2:"value2"]
Remarks: this is just more elegant but it's bad idea as it encourages people to create a new map at the right hand side.
- support everyWithIndex, anyWithIndex, collectWithIndex, sumWithIndex etc. it's even better if the original every, any has an implicit variable/syntax for retrieving the index
e.g. [10,20].collectWithIndex{ it,i -> it*(i+1) } = [ 10, 40 ]
I actually prefer all methods for collections to support the index parameter by default, without a need to use a different WithIndex method.
- In any collection closure, e.g. each, every, any etc., support it.next() and it.prev()/previous() and it.sibing(int) to retrieve the next item, return null if not existed (but no nullpointerexception)
e.g. [1,2,3,2].sort().find{ it == it.silbling(-1) } == 2
Trust me, I'm not such a demanding man when I wrote Java! :-)
Anyone second my suggestions? any more ideas?
Regards,
mingfai