The Inbox: Collections-ct.922.mcz
Posted by
commits-2 on
Dec 07, 2020; 5:46pm
URL: https://forum.world.st/The-Inbox-Collections-ct-922-mcz-tp5125152.html
A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-ct.922.mcz==================== Summary ====================
Name: Collections-ct.922
Author: ct
Time: 7 December 2020, 6:46:19.160326 pm
UUID: 633c2dcc-4586-e443-bf03-02ae9ae42ee6
Ancestors: Collections-mt.919
Proposal: Implements #add:put:during: as execution around method on Dictionary. This logic is not absolutely trivial, so I would not like to reimplement it again every time I need to build an execution around setter.
=============== Diff against Collections-mt.919 ===============
Item was added:
+ ----- Method: Dictionary>>at:put:during: (in category 'accessing') -----
+ at: key put: anObject during: aBlock
+
+ | revertBlock assoc |
+ revertBlock := self
+ at: key
+ ifPresent: [:value | [self at: key put: value]]
+ ifAbsent: [[self removeKey: key]].
+ self at: key put: anObject.
+ assoc := self associationAt: key ifAbsent: [nil].
+ ^ aBlock ensure: [
+ | newAssoc |
+ ((newAssoc := self associationAt: key ifAbsent: [nil]) == assoc
+ and: [newAssoc value = anObject])
+ ifTrue: [revertBlock value]]!