[squeak-dev] Re: InjectionNull (was Re: Re: Collection>>sum
implementation)
Paolo Bonzini
bonzini at gnu.org
Tue Aug 12 15:12:03 UTC 2008
Randal L. Schwartz wrote:
>>>>>> "Randal" == Randal L Schwartz <merlyn at stonehenge.com> writes:
>
> Randal> Yes, that solves it for SequencableCollection, but not Collection.
> Randal> I think the trouble is how to solve it for the general case.
>
> This may have been brought up before, but it just occurred to me
> that we merely need an "InjectionNull" class that answers the first
> argument in response to any message send, through a simple DNU handler.
>
> Then we could implement #reduce: as:
>
> reduce: aBlock
> self ifEmpty: [^ some exception ].
> ^self inject: InjectionNull new into: aBlock.
What about:
| iteration |
self ifEmpty: [ ^some exception ].
iteration := [ :old :each | iteration := aBlock. each ].
self do: [ :each | value := iteration value: value value: each ].
^value
Paolo
More information about the Squeak-dev
mailing list
|