The Trunk: Collections-mt.591.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Collections-mt.591.mcz

commits-2
Marcel Taeumel uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-mt.591.mcz

==================== Summary ====================

Name: Collections-mt.591
Author: mt
Time: 14 January 2015, 1:13:09.966 pm
UUID: 8d73a22f-0d76-1f4a-82b7-53900b5f3be1
Ancestors: Collections-mt.590

Added #flatten as special case for #concatenation to remove any nesting except for strings. Very simple implementation with streams and recursion but not as efficient as #concatenation.

=============== Diff against Collections-mt.590 ===============

Item was added:
+ ----- Method: SequenceableCollection>>flatten (in category 'converting') -----
+ flatten
+ "Similar to #concatenation but removes all nesting except for strings.
+ Example: {3 .4 .{2 .4 .{'hi'} .'ho'}} flatten = {3 .4 .2 .4 .'hi' .'ho'}"
+
+ ^ Array streamContents: [:stream |
+ self do: [:each |
+ (each isCollection and: [each isString not])
+ ifFalse: [stream nextPut: each]
+ ifTrue: [stream nextPutAll: each flatten]]]!


Reply | Threaded
Open this post in threaded view
|

Re: The Trunk: Collections-mt.591.mcz

Tobias Pape
Heym

On 14.01.2015, at 12:13, [hidden email] wrote:

> Marcel Taeumel uploaded a new version of Collections to project The Trunk:
> http://source.squeak.org/trunk/Collections-mt.591.mcz
>
> ==================== Summary ====================
>
> Name: Collections-mt.591
> Author: mt
> Time: 14 January 2015, 1:13:09.966 pm
> UUID: 8d73a22f-0d76-1f4a-82b7-53900b5f3be1
> Ancestors: Collections-mt.590
>
> Added #flatten as special case for #concatenation to remove any nesting except for strings. Very simple implementation with streams and recursion but not as efficient as #concatenation.
>
> =============== Diff against Collections-mt.590 ===============
>
> Item was added:
> + ----- Method: SequenceableCollection>>flatten (in category 'converting') -----
> + flatten

I know that flatten is a name for this in other languages
but IMHO `flattened` would be a better fit :)
(see #sorted, #negated, #rounded, ...)

I would expect in-place, destructive operation when reading
`flatten`, eg as with #sort


Best
        -Tobias

> + "Similar to #concatenation but removes all nesting except for strings.
> + Example: {3 .4 .{2 .4 .{'hi'} .'ho'}} flatten = {3 .4 .2 .4 .'hi' .'ho'}"
> +
> + ^ Array streamContents: [:stream |
> + self do: [:each |
> + (each isCollection and: [each isString not])
> + ifFalse: [stream nextPut: each]
> + ifTrue: [stream nextPutAll: each flatten]]]!
>
>