diff --git a/source/Buoy-Collections-GS64-Extensions/Array.extension.st b/source/Buoy-Collections-GS64-Extensions/Array.extension.st index e8b3ab5..1554cf4 100644 --- a/source/Buoy-Collections-GS64-Extensions/Array.extension.st +++ b/source/Buoy-Collections-GS64-Extensions/Array.extension.st @@ -8,3 +8,14 @@ Array >> fillFrom: aCollection with: aBlock [ aCollection do: [ :each | self at: (index := index + 1) put: (aBlock value: each) ] ] + +{ #category : #'*Buoy-Collections-GS64-Extensions' } +Array class >> newFrom: aCollection [ + "Answer an instance of me containing the same elements as aCollection." + + | newArray | + newArray := self new: aCollection size. + 1 to: aCollection size do: [ :i | + newArray at: i put: (aCollection at: i) ]. + ^ newArray +] diff --git a/source/Buoy-Collections-GS64-Extensions/Collection.extension.st b/source/Buoy-Collections-GS64-Extensions/Collection.extension.st index c387dae..14a459a 100644 --- a/source/Buoy-Collections-GS64-Extensions/Collection.extension.st +++ b/source/Buoy-Collections-GS64-Extensions/Collection.extension.st @@ -6,6 +6,15 @@ Collection >> anyOne [ ^ self any ] +{ #category : #'*Buoy-Collections-GS64-Extensions' } +Collection >> as: aSimilarClass [ + "Create an object of class aSimilarClass that has similar contents to the receiver if the object is not already an instance of this class." + + aSimilarClass == self class ifTrue: [ ^ self ]. + + ^ aSimilarClass newFrom: self +] + { #category : #'*Buoy-Collections-GS64-Extensions' } Collection >> collect: aBlock as: aClass [ "Evaluate aBlock with each of the receiver's elements as the argument. @@ -38,6 +47,16 @@ Collection >> isSequenceable [ ^ false ] +{ #category : #'*Buoy-Collections-GS64-Extensions' } +Collection class >> newFrom: aCollection [ + "Answer an instance of me containing the same elements as aCollection." + + | newCollection | + newCollection := self new: aCollection size. + newCollection addAll: aCollection. + ^ newCollection +] + { #category : #'*Buoy-Collections-GS64-Extensions' } Collection >> select: selectBlock thenCollect: collectBlock [ diff --git a/source/Buoy-Collections-GS64-Extensions/SequenceableCollection.extension.st b/source/Buoy-Collections-GS64-Extensions/SequenceableCollection.extension.st index 99275fb..8cfcc9f 100644 --- a/source/Buoy-Collections-GS64-Extensions/SequenceableCollection.extension.st +++ b/source/Buoy-Collections-GS64-Extensions/SequenceableCollection.extension.st @@ -5,3 +5,8 @@ SequenceableCollection >> isSequenceable [ ^ true ] + +{ #category : #'*Buoy-Collections-GS64-Extensions' } +SequenceableCollection >> writeStream [ + ^ WriteStream on: self +]