Skip to content

Pharo's Collections

CyrilFerlicot edited this page Oct 7, 2016 · 1 revision

I will talk a little about the mains collections of Pharo.

The most used is the OrderedCollection. When you add elements to this collection they keep the same order unless you sort them (#sort:).

As in most language there is an Array class. His size cannot be changed. You can create them with a special syntax:

  • #( 'toto' 1 true #foo ) This one can only contains literals (Strings, Booleans, Integers, Symbols…)
  • { Object new . 'toto' . MyClass createWith: 2 } This on can contains any objects.

The equivalent of a Map is a Dictionary. It will associate values to keys. The keys are unique and use the #= to know if two keys are the same. An IdentityDictionary is the same but using #==.

A Set is a non sequential collection that does not accept duplicated elements. Bag is the same but accept them.

Clone this wiki locally