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
add:appends;addFirst:cuts the queue.first,size, andremoveFirstread and reshape.do:walks the elements with a block.
Keywords and builtins used here
OrderedCollectionTranscriptcrfirstnewprintStringremoveFirstsize
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.
Step 1 of 4 in Collections, step 10 of 31 in Language basics.