[Newbies] Re: Another extension proposal -> subsets

cdrick cdrick65 at gmail.com
Thu Jul 24 16:27:48 UTC 2008


or withNicolas suggestion:

Set>>asPowerset
	| subset |
	subset := (OrderedCollection new: (2 raisedTo: self size))
		add: Set new;
		yourself.
	1 to: self size do: [:subSize | "don't copy anymore as there is the
Set conversion"
 	self asArray combinations: subSize atATimeDo: [:subArray | subset
add: subArray asSet]].
	^ subset asSet

I'd still prefer #combinationsSize:do:   instead of    #combinations:atATimeDo:

>
> How about naming
>
> Collection>>#asPowerset
>        ^ self asSet powersetInto: (Set new: (2 raisedTo: self size))
>
> with Set>>#powersetInto: and putting that into the next release.
>
> /Klaus
>


More information about the Beginners mailing list