[Pharo-project] Collection extensions

Alexandre Bergel alexandre at bergel.eu
Mon Jan 5 09:20:13 EST 2009


I vote to get these methods in.

Alexandre


On 5 Jan 2009, at 10:30, Stéphane Ducasse wrote:

> Hi all
>
> I published to the inbox some cool collection extension methods that
> we use all the time in Moose.
> flatCollect:, collectAsSet:, and groupedBy:
>
> http://code.google.com/p/pharo/issues/detail?id=432&colspec=ID%20Type%20Status%20Summary&start=100
> I would like to have your feedback because we found them really useful
> in practice.
>
> Here are some examples:
>
> testFlatCollectArray
> 	"self debug: #testFlatCollectArray"
> 	
> 	self assert: ((#((1 2) (3 4) (5 3)) flatCollect: [ :each ]) = #(1 2 3
> 4 5 3)).
> 	self assert: ((#((1 2) (2 3) (1 3 4)) flatCollect: [:each]) = #(1 2 2
> 3 1 3 4)). 	
>
> 	self assert: ((#((1 2) (2 3) (1 3 4)) flatCollect: [:each| Set with:
> each])
> 					=  #(#(1 2) #(2 3) #(1 3 4))).
>
>
> testFlatCollectSet
> 	"self debug: #testFlatCollectSet"
> 	
> 	self assert: ((#((1 2) (1 2) (1 3 4)) asSet  flatCollect: [:each]) =
> #(1 1 2 3 4) asSet).
> 	self assert: ((#() asSet flatCollect: [:each]) = #() asSet).
>
> 	self assert:  ((#((1 2) () (1 3 4)) asSet  flatCollect: [:each]) =
> #(1 1 2 3 4) asSet).
> 	self assert:  ((#((1 2) #((99)) (1 3 4)) asSet  flatCollect: [:each])
> 					= #(1 1 2 3 4 (99)) asSet).
> 	self assert:  ((#((1 2) #(()) (1 3 4)) asSet  flatCollect: [:each])
> 					= #(1 1 2 3 4 ()) asSet).			
>
>
> testGroupedByArray
> 	"self debug: #testGroupedByArray"
> 	
> 	| res |
> 	res := #(1 2 3 4 5) groupedBy: [:each | each odd].
> 	self assert:   (res at: true) = #(1 3 5).
> 	self assert: (res at: false) = #(2 4)
>
>
> testGroupedBy
> 	"self debug: #testGroupedBy"
> 	
> 	| res |
> 	res := #(1 2 3 4 5) asOrderedCollection
> 				groupedBy: [:each | each odd].
> 	self assert:   (res at: true) = #(1 3 5) asOrderedCollection.
> 	self assert: (res at: false) = #(2 4) asOrderedCollection
>
>
> _______________________________________________
> Pharo-project mailing list
> Pharo-project at lists.gforge.inria.fr
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>

-- 
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.









More information about the Pharo-dev mailing list