[Squeak] Newbie permutations

Richard A. O'Keefe ok at cs.otago.ac.nz
Wed Apr 10 04:02:51 UTC 2002


Writing about #permutationsDo:, "Brian T. Rice" <water at tunes.org> suggested
	The compromise is to introduce a way to pipe out permutations one at a 
	time onto a stream, maybe permutationsOnStream: and have the stream pull 
	them as necessary, probably at the request of the stream-consumer.
	
I'm just typing aloud here, but isn't the problem (of having x do: aBlock
but not x collect: aBlock and so on) rather more general than permutations,
and one which could be solved in an OO way?

Something like this.
    (IterationAdapter on: #(1 3 5) selector: #permutationsDo:)
	select: [:each| ...] thenCollect: [:selected| ...]

I've now written such a class and it will appear shortly as an [ENH].
So much code had to be duplicated between this and Collection,
and could not be inherited because an IterationAdapter _isn't_ a
Collection, that a refactoring where IterationAdapter and Collection
became children of a new IterationSupporter class would seem to be
called for.  But before anything like that should be done,
IterationAdapter ought to be generalised to let you wrap iteration
code around a read stream.



More information about the Squeak-dev mailing list