Exploring the Smalltalk Collections API in unit tests using Pharo 8.0

https://pharo.org/

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

Select

Filtering fruit using the select: method

Reject

Filtering fruit using the reject: method

Collect

Transforming fruit using the collect: method

FlatCollect

Flattening the characters in fruit using the flatCollect: method

Detect / DetectIfNone

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

InjectInto

Concatenating the fruit in a collection using inject:into:

GroupedBy

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

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

https://play.google.com/store/apps/details?id=com.appeanmoneyonline.freeapp2021&referrer=utm_source%

Variables in Java:

… Made Richer with Functional Values

Find Out What Else Influences the Architecture

images/architecture_influencers.png

by Dwayne Phillips

The Path to Coding: Operation Code DC Welcomes Code.gov to Their October Meetup

[EOS Contracts in Depth] eosio.forum Part 3: Source Code Walkthrough

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

Fixing JWT Insecure Session Termination by Blacklisting Tokens

KivaKit — Type Conversion

Tomcat Server — Invalid Character in Request

Create SQL cache stores and more in Data Grid 8.3