[squeak-dev] Dictionary >> #at:ifAbsentPut:ifPresentPut:
Thiede, Christoph
Christoph.Thiede at student.hpi.uni-potsdam.de
Fri Apr 30 16:36:20 UTC 2021
Hi all,
recently I stumbled upon an extension method for Dictionary which *might* fit well into the Trunk:
Dictionary >> #at: key ifAbsentPut: startBlock ifPresentPut: nextBlock
"(c) 2020 Basti Kruck und Marcel Taeumel. :-)" (self includesKey: key) ifFalse: [
^ self at: key put: startBlock value]. ^ self
at: key
put: (nextBlock value: (self at: key))
See https://github.com/hpi-swa/vivide/blob/c4ac5ea562bd563358d52ee41c149a3fbcffd90e/repository/Vivide.package/Dictionary.extension/instance/at.ifAbsentPut.ifPresentPut..st.
Usage:
counter := counters at: key ifAbsentPut: [0] ifPresentPut: [:i | i + 1]
What do you think, should we copy this into the Trunk? Or is it just fine to do something like this instead at the sender side:
counter := counters at: key put: (counters at: key ifAbsent: [0] ifPresent: [:i | i + 1])
<http://www.hpi.de/>
Also, I'm not sure about the order of arguments.
Best,
Christoph
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20210430/12dad2d4/attachment.html>
More information about the Squeak-dev
mailing list
|