Fwd: Robust flatten for collection?

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

Fwd: Robust flatten for collection?

Simon Denier-3


Begin forwarded message:

From: Simon Denier <[hidden email]>
Date: 27 août 2010 14:06:42 HAEC
To: A friendly place where any question about pharo is welcome <[hidden email]>
Cc: Simon Denier <[hidden email]>
Subject: Robust flatten for collection?

Hi there

A question to test your sagacity :)

I'm looking for a method which would flatten a collection, regardless of whether the collection is already flat or not.


that is:
#((1 2 3) (4 5 6)) flatten  --> #(1 2 3 4 5 6)

#(1 2 3 4 5 6) flatten  --> #(1 2 3 4 5 6)

#((1 2 3) 4 5 6) flatten  --> #(1 2 3 4 5 6)


Any idea about the best implementation for this?


--
Simon




--
 Simon




_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Robust flatten for collection?

Alexandre Bergel
There is an implementation of flatten in Pharo that almost does what you want.
>> #((1 2 3) (4 5 6)) flatten  --> #(1 2 3 4 5 6)

ok

>> #(1 2 3 4 5 6) flatten  --> #(1 2 3 4 5 6)
>> #((1 2 3) 4 5 6) flatten  --> #(1 2 3 4 5 6)

raises error

Alexandre


On 27 Aug 2010, at 08:58, Simon Denier wrote:

>
>
> Begin forwarded message:
>
>> From: Simon Denier <[hidden email]>
>> Date: 27 août 2010 14:06:42 HAEC
>> To: A friendly place where any question about pharo is welcome <[hidden email]>
>> Cc: Simon Denier <[hidden email]>
>> Subject: Robust flatten for collection?
>>
>> Hi there
>>
>> A question to test your sagacity :)
>>
>> I'm looking for a method which would flatten a collection, regardless of whether the collection is already flat or not.
>>
>>
>> that is:
>> #((1 2 3) (4 5 6)) flatten  --> #(1 2 3 4 5 6)
>>
>> #(1 2 3 4 5 6) flatten  --> #(1 2 3 4 5 6)
>>
>> #((1 2 3) 4 5 6) flatten  --> #(1 2 3 4 5 6)
>>
>>
>> Any idea about the best implementation for this?
>>
>>
>> --
>> Simon
>>
>>
>>
>
> --
>  Simon
>
>
>
> _______________________________________________
> Moose-dev mailing list
> [hidden email]
> https://www.iam.unibe.ch/mailman/listinfo/moose-dev

--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.






_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev