Skip to content

Commit abcdb26

Browse files
authored
Merge pull request #19644 from MarcusDenker/19625-Error-sending-flatCollect-to-OrderedDictionary
19625-Error-sending-flatCollect-to-OrderedDictionary
2 parents 515e90c + 2583e9e commit abcdb26

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

src/Collections-Sequenceable-Tests/OrderedDictionaryTest.class.st

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,15 @@ OrderedDictionaryTest >> testEqualsWhenKeyArentInTheSameOrder [
874874
assertDictionary: dictionaryOne doesNotEqual: dictionaryTwo.
875875
]
876876

877+
{ #category : 'testing' }
878+
OrderedDictionaryTest >> testFlatCollect [
879+
880+
| res |
881+
res := {#first -> -1. #second -> 5 . #three -> -33} as: OrderedDictionary.
882+
res := res flatCollect: [ :e | { e abs } ].
883+
self assert: res asSet equals: #(1 5 33) asSet
884+
]
885+
877886
{ #category : 'tests' }
878887
OrderedDictionaryTest >> testHash [
879888
| dictionary otherDictionary internalDictionary otherInternalDictionary |

src/Collections-Sequenceable/OrderedDictionary.class.st

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,16 @@ OrderedDictionary >> errorInvalidIndex: anIndex [
306306
SubscriptOutOfBounds signalFor: anIndex
307307
]
308308

309+
{ #category : 'enumerating' }
310+
OrderedDictionary >> flatCollect: aBlock [
311+
"Evaluate aBlock for each of the receiver's values (by opposition to keys) and answer the
312+
list of all resulting values flatten one level. Assumes that aBlock returns some kind
313+
of collection for each element. Equivalent to the lisp's mapcan"
314+
"If you want to have keys use associations collect: or associations flatCollect: "
315+
316+
^ self flatCollect: aBlock as: OrderedCollection
317+
]
318+
309319
{ #category : 'private' }
310320
OrderedDictionary >> growOrderedKeys [
311321
orderedKeys :=

0 commit comments

Comments
 (0)