[squeak-dev] Collection's #fold: vs #reduce:
siguctua at gmail.com
Tue Nov 2 21:17:17 UTC 2010
> fold: aBinaryBlock
> "Evaluate the block with the first two elements of the receiver,
> then with the result of the first evaluation and the next element,
> and so on. Answer the result of the final evaluation. If the receiver
> is empty, raise an error. If the receiver has a single element, answer
> that element."
> #('if' 'it' 'is' 'to' 'be' 'it' 'is' 'up' 'to' 'me') fold: [:a :b | a, '
> ', b]
just a 0.5 penny..
wow.. you trying to get a fastest way to fold a string,
by using a concatenaiton.. i think its not most effective way, at
least for given example :)
I think that using streams, it will be much faster.
(String streamContents: [:s |
(#('if' 'it' 'is' 'to' 'be' 'it' 'is' 'up' 'to' 'me') do: [:each | s
nextPutAll: each; nextPut: $ ]) allButLast
Igor Stasenko AKA sig.
More information about the Squeak-dev