The Inbox: Collections-mt.840.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Inbox: Collections-mt.840.mcz

commits-2
A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-mt.840.mcz

==================== Summary ====================

Name: Collections-mt.840
Author: mt
Time: 11 July 2019, 5:44:50.457612 pm
UUID: ce7e6999-68aa-a642-9fda-d74f42b3233b
Ancestors: Collections-mt.839

Propose more readable symbol-lookup interface to (1) replace #hasInterned:ifTrue: and (2) avoid ifNil-checks in plain #lookup: use.

Interface is inspired by Collection >> #detect:ifFound:ifNone:.

=============== Diff against Collections-mt.839 ===============

Item was changed:
  ----- Method: Symbol class>>lookup: (in category 'instance creation') -----
  lookup: aStringOrSymbol
 
+ ^ self lookup: aStringOrSymbol ifFound: [:symbol | symbol] ifNone: nil!
- | originalNewSymbols originalSymbolTable |
- originalNewSymbols := NewSymbols.
- originalSymbolTable := SymbolTable.
- ^(originalNewSymbols like: aStringOrSymbol) ifNil: [
- originalSymbolTable like: aStringOrSymbol ]!

Item was added:
+ ----- Method: Symbol class>>lookup:ifFound: (in category 'instance creation') -----
+ lookup: aStringOrSymbol ifFound: aBlock
+
+ ^ self lookup: aStringOrSymbol ifFound: aBlock ifNone: nil
+ !

Item was added:
+ ----- Method: Symbol class>>lookup:ifFound:ifNone: (in category 'instance creation') -----
+ lookup: aStringOrSymbol ifFound: foundBlock ifNone: exceptionBlock
+
+ | originalNewSymbols originalSymbolTable |
+ originalNewSymbols := NewSymbols.
+ originalSymbolTable := SymbolTable.
+ ^ (originalNewSymbols like: aStringOrSymbol)
+ ifNotNil: [:symbol | foundBlock value: symbol]
+ ifNil: [(originalSymbolTable like: aStringOrSymbol)
+ ifNotNil: [:symbol | foundBlock value: symbol]
+ ifNil: [exceptionBlock value]]!

Item was added:
+ ----- Method: Symbol class>>lookup:ifNone: (in category 'instance creation') -----
+ lookup: aStringOrSymbol ifNone: exceptionBlock
+
+ ^ self lookup: aStringOrSymbol ifFound: [:symbol | symbol] ifNone: exceptionBlock!