2017-04-24 16:10 GMT-03:00 Ramon Leon <ramon.leon@allresnet.com>:
On 04/24/2017 11:16 AM, Esteban A. Maringolo wrote:>
For these use cases it would be nice to have some sort of syntax sugar as with the cascade operator, but with a chaining operator instead.
This doesn't even require syntactic sugar, just objects, and this is a more general problem even with a back to back chain of select/detect/reject style things. I solved this for myself years ago by introducing what I call a pipe (nod to unix) allowing me to chain calls in a pipeline without all the parens with each call acting on the result value of the last call. Trivially implemented using #doesNotUnderstand: and the cascade operator.
^ dict1 asPipe at: 'key1'; at: 'key2'; at: 'key3'.
Anytime I have a bunch of back to back calls that would require a lot of parens, I just create a pipe...
maxRoomsAvailable ^self findBlocks asPipe select: [ :e | e blockDate between: actualCheckInDate and: actualCheckInDate + (nights - 1) days ]; detectMin: [ :e | e quantityAvailable ]; quantityAvailable
Very neat implementation. I think this simple class could come as part of the base image :) Esteban A. Maringolo