Skip to content

Commit

Permalink
Add Collection>>#collect:as: to GS package
Browse files Browse the repository at this point in the history
  • Loading branch information
gcotelli committed Aug 8, 2023
1 parent c82aa2a commit 870b43a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 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,24 @@ Collection >> anyOne [
^ self any
]

{ #category : #'*Buoy-Collections-GS64-Extensions' }
Collection >> collect: aBlock as: aClass [
"Evaluate aBlock with each of the receiver's elements as the argument.
Collect the resulting values into an instance of aClass. Answer the resulting collection."

^(aClass new: self size) fillFrom: self with: aBlock
]

{ #category : #'*Buoy-Collections-GS64-Extensions' }
Collection >> fillFrom: aCollection with: aBlock [
"Private.
Evaluate aBlock with each of aCollections's elements as the argument.
Collect the resulting values into self. Answer self."

aCollection do: [ :each |
self add: (aBlock value: each) ]
]

{ #category : #'*Buoy-Collections-GS64-Extensions' }
Collection >> ifEmpty: emptyBlock ifNotEmpty: notEmptyBlock [

Expand Down

0 comments on commit 870b43a

Please sign in to comment.