(newbie) String / Array / ArrayedCollection

nicolas cellier ncellier at ifrance.com
Wed Feb 8 02:46:46 UTC 2006


Still about the sumOf: maxOf: etc... extensions,

Travis Griggs suggested on vwnc list that these where not absolutely necessary 
if you have a class capable of lazy evaluation on collections:

This message is expensive on large collections, because two loops:
 (aCollection collect: [:each | each squared]) sum

This message is less expensive (one loop):
 (aCollection sumOf: [:each | each squared])

This one is not expensive and more general, because it can handle sumOf: 
maxOf: etc...
 (aCollection compute: [:each | each squared]) sum

compute: does evaluate nothing, it just create a proxy with aCollection and 
block as inst var.

Evaluation is deferred untill the proxy is accessed with:
at: index
 ^function value: (input at: anIndex)
superclass max will call at: index, that's all that simple.

I think i saw such a class in squeak once, so no use to do it again.
Anybody knows where i can find it ?




More information about the Squeak-dev mailing list