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. 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 "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) ] And you'd call it like: responsePayload at: each ifPresentPut: [ :uuid | uuid asString ]. or: responsePayload at: each ifPresentPut: [ 'FooBaz' ]. Regards, Esteban A. Maringolo