Mingfai schrieb:
> hi,
>
> after programmed Groovy for a while, I've got a wish list for syntax/API
> improvement.
>
> 1. 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]
you could work on a sublist.
> 2. 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.
(3 !in in [2,3,4]) is equal to (!(3 in [2,3,4]))
> 3. 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.
true... not to forget that you can do: map[key2] = value2
> 4. 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 am against all these withIndex methods... they are polluting the API
so much. I would like to have a more general solution, but I can't think
of any yet
[...]
> 5. 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
"it" is no iterator, "it" is the actual value. Adding these methods to
the value for example by using categories may hide an existing method
bye blackdrag
--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead (
http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/http://www.g2one.com/---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email