2016-03-21 17:43 GMT-03:00 Nicolai Hess <nicolaihess@gmail.com>:
What is your implementation with with:collection: ?
I know this function from python, they call it "zip"
we could implement this in SequenceableCollection
SequenceableCollection>>zip: aCollection | index | index := 0. self size > aCollection size ifTrue:[ ^ aCollection zip: self]. ^ self class new: (aCollection size + self size) streamContents: [:stream | aCollection do: [:each | index:=index + 1. stream nextPut: each ] separatedBy: [(index > self size) ifFalse:[stream nextPut: (self at:index) ]]]
Another example, using a generator (I didn't used Generator before, but I like the idea to create an endless stream from a string, with some fill value (empty string in this case)).
|gen| gen := Generator on:[:g | '123' do:[:k | g yield: k asString ] . [true] whileTrue:[g yield:'']]. String streamContents:[:stream | 'abcdefg' do:[:c | stream nextPut: c] separatedBy:[ stream nextPutAll:gen next]]
I use those all the time (filling matrices etc). It would be nice to have something like these: '2' repeatJoin: 4 ==> '2222' 2 repeatJoin: 4 ==> 2222 '2' repeat: 4 ==> #('2' '2' '2' '2') 2 repeat: 4 ==> #(2 2 2 2) What do you think? Hernán