2008-12-09

Doing without

Reading a recent post by Ramon Leon, a thought occurred to me: In many cases, there's a better alternative to using #copyWithout:. The alternative would be to use #do:without:, implemeted as follows:
    do: block1 without: anElement
        self do: [:each | each = anElement ifFalse: [block1 value: each]]
The advantage should be obvious: It avoids making a "throw away" copy of the initial collection.

No comments:

Post a Comment