jastrachan | 29 Mar 19:37 2004
Picon

Re: Map Missing functionality


On 29 Mar 2004, at 16:45, Shakeel Mahate wrote:

> The Groovy Quick Start page seems to imply that collect, find, findAll,
> inject, every, any, join methods would work with both List and Map
> collections.
>
> However if you try to do a collect on a Map it fails.  I haven't tried
> verifying whether all of the above methods apply to Map
>
>   deps = [
>     'tophat':[],
>     'bowtie':['shirt'],
>     'socks':[],
>     'pocketwatch':['vest'],
>     'vest':['shirt'],
>     'shirt':[],
>     'shoes':['trousers', 'socks'],
>     'cufflinks':['shirt'],
>     'gloves':[],
>     'tailcoat':['vest'],
>     'underpants':[],
>     'trousers':['underpants']
>   ]
>
> The line below fails
>   dead = deps collect { item | false }
>
> I can achieve the same with the following two lines
>   dead = [:]
>   deps.each { item | dead.put(item.key, false) }

Hmm - seems to work fine for me with CVS HEAD...

Lets get Groovy!
================
Version: 1.0-rc1-snapshot JVM: 1.4.2-34
Type 'exit' to terminate the shell
Type 'help' for command help

1> m = ['a':123, 'b':456]
2> go

1> r = m.collect { false }
2> go

1> println r
2> go
[false, false]

1> println m.collect { it.value }
2> go
[123, 456]

James
-------
http://radio.weblogs.com/0112098/

Gmane