Skip to content

Commit

Permalink
Add Collection>>#as: and SequenceableCollection>>#writeStream
Browse files Browse the repository at this point in the history
  • Loading branch information
gcotelli committed Aug 8, 2023
1 parent 2f6d27a commit e8786e8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
11 changes: 11 additions & 0 deletions source/Buoy-Collections-GS64-Extensions/Array.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
19 changes: 19 additions & 0 deletions source/Buoy-Collections-GS64-Extensions/Collection.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 [

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ SequenceableCollection >> isSequenceable [

^ true
]

{ #category : #'*Buoy-Collections-GS64-Extensions' }
SequenceableCollection >> writeStream [
^ WriteStream on: self
]

0 comments on commit e8786e8

Please sign in to comment.