typestar

OrderedCollection in Smalltalk

The growable list that keeps arrival order.

"OrderedCollection grows as needed and keeps arrival order."
| queue |
queue := OrderedCollection new.
queue add: 'broadside'; add: 'chapbook'; add: 'wedding suite'.
queue addFirst: 'rush job'.

Transcript show: 'First: ', queue first; cr.
Transcript show: 'Jobs: ', queue size printString; cr.

queue removeFirst.
queue do: [:job | Transcript show: '- ', job; cr].

Transcript show: (queue includes: 'chapbook') printString; cr.

How it works

  1. add: appends; addFirst: cuts the queue.
  2. first, size, and removeFirst read and reshape.
  3. do: walks the elements with a block.

Keywords and builtins used here

The run, in numbers

Lines
13
Characters to type
429
Tokens
71
Three-star pace
60 tpm

At the three-star pace of 60 tokens a minute, this run takes about 71 seconds.

Type this snippet

Step 1 of 4 in Collections, step 10 of 31 in Language basics.

← Previous Next →