[squeak-dev] Dictionary >> #at:ifAbsentPut:ifPresentPut:
Tobias Pape
Das.Linux at gmx.de
Fri Apr 30 17:05:54 UTC 2021
Hi
> On 30. Apr 2021, at 18:36, Thiede, Christoph <Christoph.Thiede at student.hpi.uni-potsdam.de> wrote:
>
> 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])
>
> Also, I'm not sure about the order of arguments.
I find it a bit too specific for trunk.
It's quite an edge case...
-t
More information about the Squeak-dev
mailing list
|