Hi,

 

I am using a nice little method #destructDo: for a while now and it feels good.

In VisualWorks:

SequenceableCollection>>destructDo: aBlock

                                "Evaluate aBlock with the receiver's elements as parameters.

                                aBlock takes its arguments from the receiver.

                                'ok'

                                #(1 2 3) destructDo: [:a :b :c | a + b + c]

                                #(1 2 3) destructDo: [:a :b | a + b]

                                #(1 2 3) destructDo: [:a | a]

                                #(1 2 3) destructDo: [42]

                                'not ok'

                                #(1 2 3) destructDo: [:a :b :c :d | a + b + c + d]

                                "

                                ^aBlock cullWithArguments: self asArray

 

In Amber:

SequenceableCollection>>destructDo: aBlock

                                ^aBlock valueWithPossibleArguments: self

 

In Pharo and other dialects, I don’t know, but should be as easy.

 

For example you can do

                (('2020-03-28' tokensBasedOn: $-) collect: #asNumber) destructDo: [:year :month :day |

                               Date newDay: day monthNumber: month year: year]

 

I like that the block is not the receiver (like with #valueWithArguments or #cullWithArguments), but the last argument.

 

Now the questions:

 

Happy hacking,

                Christian