Happy !
zeroflag / Chain
About Chain
This is a very simple extension that lets you chain keyword messages without using lots of parentheses.
Instead of this:
(((#('apple' 'peach' 'banana')
groupedBy: #size)
select: [:each | each size even])
values)
collect: #asCommaString.
You can write this:
#('apple' 'peach' 'banana') chain
groupedBy: #size;
select: [ :each | each size even ];
values;
collect: #asCommaString
The chain returns a proxy that sends the cascaded messages to the object returned by the previously sent message.
The DNU handler of the proxy is implemented as follows:
doesNotUnderstand: aMessage
target := aMessage sendTo: target.
^ target
You can use an alternative form of the chain message to simulate something like the "safe navigation operator" or maybe monad.
item recipient address street. "this will fail if any of the intermediate result is nil"
item safeChain recipient; address; street. "this will return nil imediately if any of the intermediate result is nil"
