31 Mar 2005 17:43
Re: Re: [groovy-dev] RE: Some enhanced methods for collection
FWIW Java does both as well. Arrays.asList(array) array = Collection.toArray() On 31 Mar 2005, at 16:36, Aaron Alpar wrote: > Hrumph... > > toXxxx is a Java convention... > asXxxx is a Groovy/Smalltalk/Ruby convention. > > I say stick to the asXxxx because it's a Groovy extension. > > Leave the toXxxx stuff for the original Java methods, this is also > kinda > nice because if Java *does* implement a toSet for list, then we don't > get a name collision for the method, and have the _option_ of removing > the duplicate method from Groovy. > > - Aaron > > On Wed, 2005-03-30 at 23:49, Dierk Koenig wrote: >> toSet() reads nicer in expressions like >> >> println String.class.methods.name.toSet().sort() >> >> where 'as Set' reads nicer in declarations and single assignment like >> >> l = someotherlist as Set >> >> How about having both? >> >> cheers >> Mittie >> >>> -----Original Message----- >>> From: jastrachan@... [mailto:jastrachan@...] >>> Sent: Donnerstag, 31. Marz 2005 9:27 >>> To: jsr@... >>> Subject: Re: [groovy-jsr] Re: [groovy-dev] RE: Some enhanced methods >>> for >>> collection >>> >>> >>> FWIW there are a few methods around like toList() and toArray(), >>> maybe >>> we need a toSet()? >>> >>> I do quite like >>> >>> list as Set >>> >>> too (allowing folks to specify the exact Set implementation if they >>> wish) >>> >>> >>> On 30 Mar 2005, at 22:10, John Rose wrote: >>>> On Mar 30, 2005, at 11:47, Dierk Koenig wrote: >>>>> For the use of imperative verbs: how would this relate to >>>>> - compact >>>>> - unique >>>>> - sort (hehe) >>>>> what would be the non-imperative versions that returns the copy? >>>> >>>> I'm not saying that all of these merit fresh-copy versions, but they >>>> could be named: >>>> >>>> list.compacted() >>>> list.withCompaction() >>>> list.copyCompact() >>>> >>>> list.sort() >>>> list.sorted() >>>> list.copySort() >>>> list as SortedSet // this is nice and clear, but no duplicates >>>> allowed >>>> list as SortedList // not a real type, although Smalltalk has it >>>> >>>> After doing a bunch of these examples, the "copyFrob" convention may >>>> start looking superior. >>>> >>>> I do not like the name list.unique(), because the word is an >>>> adjective, which makes the grammar unclear. >>>> I prefer Common Lisp's very explicit verb phrase: >>>> list.removeDuplicates(). >>>> >>>> -- John >>>> >>>> >>> >>> James >>> ------- >>> http://radio.weblogs.com/0112098/ >>> > > James ------- http://radio.weblogs.com/0112098/
RSS Feed