On 12/01/17 12:32, Henrik Nergaard wrote:
Shouldn't these two code snippets behave the same way?
#flatCollect: expects that aBlock returns a collection for each element (see
method comment) and only flattens one level, while # flattened expands all sub
collections it finds:
----------------------------------------------------------------
#( #(1 #(2) ) ) flatCollect: [ :x | x ]. "#(1 #(2))"
#( #(1 #(2) ) ) flattened. "#(1 2)"
----------------------------------------------------------------
Oh, ok so it's a feature :)
Ps. Using a symbol instead of a block reduces performance.
[ 1 to: 1e9 do: [ :each | each ] ] timeToRun. "0:00:00:02.463"
[ 1 to: 1e9 do: #yourself ] timeToRun. "0:00:00:11.468"
Wow, I used symbols to make the example clear but I didn't know that.
That's sad, I think it is sexier to use a symbol to do this kind of
things. :(
Regards,
Julien