Exploring the Smalltalk Collections API in unit tests using Pharo 8.0


A Little Smalltalk for the Holidays

Learn Smalltalk in Y minutes

Syntax used in the examples

Object-Oriented Basics

Object param1, param2, param3;SomeClass object = new SomeClass();
Object result1 = object.method();
Object result2 = object.withOne(param1);
Object result3 = object.withOneTwo(param1, param2);
Object result4 = object.withOneTwoThree(param1, param2, param3);
| object param1 param2 param3 result1 result2 result3 result4 |object := SomeClass new.
result1 := object method.
result2 := object withOne: param1.
result3 := object withOne: param1 two: param2.
result4 := object withOne: param1 two: param2 three: param3.

Smalltalk Collection methods covered in this blog

  • ,
  • =
  • asBag
  • assert: / assert:equals: / deny:
  • asUppercase
  • first
  • includes:
  • ifTrue:ifFalse:
  • isEmpty
  • newFromKeys:andValues:
  • occurrencesOf:
  • with:
  • Bag
  • OrderedCollection
  • OrderedDictionary
  • Set

Smalltalk Iteration Patterns


Filtering fruit using the select: method


Filtering fruit using the reject: method


Transforming fruit using the collect: method


Flattening the characters in fruit using the flatCollect: method

Detect / DetectIfNone

Finding the fruit that starts with a letter using detect: and detect:ifNone:


Concatenating the fruit in a collection using inject:into:


The method groupedBy: used to group fruit by the first character

AnySatisfy / AllSatisfy / NoneSatisfy

Examples of the method anySatisfy:
Examples of the method allSatisfy:
Examples of the method noneSatisfy:


Count all the bananas and fruit that contains the letter $a

The Source

That’s all folks!




Java Champion. Creator of the Eclipse Collections OSS Java library (http://www.eclipse.org/collections/). Inspired by Smalltalk. Opinions are my own.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Migrating from Compute Engine to Kubernetes Engine with Migrate for Anthos

3 steps to clean comment

How To Be Hyper-Productive & Avoid Multi User Database Issues With Cost Estimating Software.

Downrunner: Beyond Jupyter

A picture of an org chart

Bring Your Code to the Snowflake Data Cloud with Snowpark

Advice from a HW7 Winning Team: Dance Party

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Donald Raab

Donald Raab

Java Champion. Creator of the Eclipse Collections OSS Java library (http://www.eclipse.org/collections/). Inspired by Smalltalk. Opinions are my own.

More from Medium

An In-Depth Guide to Java Records

Reactive Programming with Reactor Library

SOLID principles: The Open-Closed Principle (Part II)

Where to Log Exceptions