Esteban A. Maringolo wrote:
2017-08-08 17:49 GMT-03:00 Esteban Lorenzano<esteba...@gmail.com>:
Extension. Helpers are for javaers.


Extensions are concise, and right to the point, but as long as they
stay in your private image or prove of value to everybody else both in
function and selector naming.

My guides are:
A. If it's your image, extend Dictionary, Object or whatever you want.
It's your mess, your image, your rules.\

True.

B. If you're going to share the code with others (as a library), then
you should check whether the selectors clash with existing ones, or
have "side effects".
C. If it's going in the "core" image, then the selector should be well
thought, having broad application semantics and coherence with the
existing selectors, like the current #at:ifAbsent:, #at:ifPresent:,
etc.

In this case I'd go for something like:

Dictionary>>#at: key ifPresentPut: aBlock

Never imagined it should be at:ifPresentPut:. Not clear at the first sight, but undobutedly it is the best pick, on the second one.

     "Lookup the given key in the receiver. If it is present, update it
with the value of evaluating the given block with the value associated
with the key. Otherwise, answer nil."

      ^self at: key ifPresent: [ :object | self at: key put: (aBlock
cull: object) ]

Well, if it is seen as a thing of value, you or someone can add it to pharo7 (I probably can not, not having and not wanting to have github account). Maybe for Array / String as well.

And you'd call it like:
   responsePayload at: each ifPresentPut: [ :uuid | uuid asString ].

In my case, `responsePayload at: each ifPresentPut: #asString` probably. I don't care for a bit of perf hit (I like Symbol >> value:, during Amber development I often do `Smalltalk packages do: #commit` to commit everything and see what changed in git diff).

or:
   responsePayload at: each ifPresentPut: [ 'FooBaz' ].


Regards,

Esteban A. Maringolo

Thanks, Herby

Reply via email to