Skip to content

Commit

Permalink
Merge pull request #4594 from kasperosterbye/2845-Error-in-Collection…
Browse files Browse the repository at this point in the history
…flatCollect-b-as-String

2845-Error-in-CollectionflatCollect-b-as-String
  • Loading branch information
MarcusDenker committed Sep 19, 2019
2 parents e47525e + 13a9eca commit 4e29b17
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Collections-Abstract/Collection.class.st
Expand Up @@ -695,11 +695,11 @@ Collection >> flatCollect: aBlock as: aCollectionClass [
"Evaluate aBlock for each of the receiver's elements and answer the
list of all resulting values flatten one level. Assumes that aBlock returns some kind
of collection for each element. Equivalent to the lisp's mapcan"

| col |
col := aCollectionClass new: self size.
self do: [ :each |
col addAll: (aBlock value: each) ].
^col
col := OrderedCollection new: self size.
self do: [ :each | col addAll: (aBlock value: each) ].
^ aCollectionClass withAll: col
]

{ #category : #enumerating }
Expand Down
8 changes: 7 additions & 1 deletion src/Collections-Tests/TEnumeratingTest.trait.st
Expand Up @@ -49,7 +49,13 @@ TEnumeratingTest >> testFlatCollectAs [

self
assert: (self simpleCollection flatCollect: [ :x | { x }, { x } ] as: IdentitySet)
equals: self simpleCollection asIdentitySet
equals: self simpleCollection asIdentitySet.
self
assert: (#(foo bar baz) flatCollect: #yourself as: String)
equals: 'foobarbaz'.
self
assert: (#(#(1 2) #(4 3)) flatCollect: #yourself as: Array)
equals: #(1 2 4 3)
]

{ #category : #'tests - enumerating' }
Expand Down

0 comments on commit 4e29b17

Please sign in to comment.