Search code examples
collectionssmalltalk

Adding collections from different instances


I am new to Smalltalk and I am trying to do a very simple program that would produce a single collection, out of multiple collections in this way:

Let's say I have a Set of Armories, and every Armory has it's own Weapons Set, what I would like to do is to write a method that would return a single collection with all the Weapons from every Armory combined.

Thanks in advance for your help!


Solution

  • Try something like this:

    armories inject: OrderedCollection new into: [:collection :armory |
       collection addAll: armory weapons; yourself].