>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)" ----------------------------------------------------------------
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" Best regards, Henrik -----Opprinnelig melding----- Fra: Pharo-dev [mailto:[email protected]] På vegne av Julien Delplanque Sendt: 12 January 2017 11:27 Til: Pharo Development List <[email protected]> Emne: [Pharo-dev] collection flatCollect: #something VS (collection collect: #something) flattened Hello everyone, While using #flatCollect: on a collection, I realized that, for example, these two code snippets do not behave the same way: #(1 (1)) flatCollect: #yourself. "Raise an error because the array does not contain only collections" (#(1 (1)) collect: #yourself) flattened "Returns #(1 1) Shouldn't these two code snippets behave the same way? Thanks in advance for your answers. Regards, Julien
