behavior of flatten?

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

behavior of flatten?

simondenier
I'm a bit surpised...

I want to flatten a collection with 'mixed' entries, like this one {{1. 2. 3}. 4} -> {1. 2. 3. 4}

However it appears that #flatten does not work, because it expects that all elements in the collection are themselves collections.
so
{{1. 2. 3}. {4}} flatten -> {1. 2. 3. 4} works
but
{{1. 2. 3}. 4} flatten -> raises error because of a dnu on 4

Anyone knows the right method which would work for my case?

--
Simon Denier




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

Re: behavior of flatten?

simondenier
They say: if you want something done right, do it yourself. So... :)

I added a #deepFlatten message in the Collection protocol in *collectionextensions.
See the tests for the specs

In short, deepFlatten doesn't mind flat collections as well as multi-level collecions.

#( (1 2) ( (4 5) 3) ) deepFlatten --> #(1 2 4 5 3)

#( 5 ( (3) ) ) deepFlatten --> #(5 3)

It also preserves strings
#( ('foo' ('bar') ) 'zorg' ) deepFlatten --> #('foo' 'bar' 'zorg')



On 4 févr. 2011, at 18:39, Simon Denier wrote:

> I'm a bit surpised...
>
> I want to flatten a collection with 'mixed' entries, like this one {{1. 2. 3}. 4} -> {1. 2. 3. 4}
>
> However it appears that #flatten does not work, because it expects that all elements in the collection are themselves collections.
> so
> {{1. 2. 3}. {4}} flatten -> {1. 2. 3. 4} works
> but
> {{1. 2. 3}. 4} flatten -> raises error because of a dnu on 4
>
> Anyone knows the right method which would work for my case?
>
> --
> Simon Denier
>
>
>

--
Simon Denier




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

Re: behavior of flatten?

Tudor Girba
Sounds good.

Doru


On 4 Feb 2011, at 23:42, Simon Denier wrote:

> They say: if you want something done right, do it yourself. So... :)
>
> I added a #deepFlatten message in the Collection protocol in *collectionextensions.
> See the tests for the specs
>
> In short, deepFlatten doesn't mind flat collections as well as multi-level collecions.
>
> #( (1 2) ( (4 5) 3) ) deepFlatten --> #(1 2 4 5 3)
>
> #( 5 ( (3) ) ) deepFlatten --> #(5 3)
>
> It also preserves strings
> #( ('foo' ('bar') ) 'zorg' ) deepFlatten --> #('foo' 'bar' 'zorg')
>
>
>
> On 4 févr. 2011, at 18:39, Simon Denier wrote:
>
>> I'm a bit surpised...
>>
>> I want to flatten a collection with 'mixed' entries, like this one {{1. 2. 3}. 4} -> {1. 2. 3. 4}
>>
>> However it appears that #flatten does not work, because it expects that all elements in the collection are themselves collections.
>> so
>> {{1. 2. 3}. {4}} flatten -> {1. 2. 3. 4} works
>> but
>> {{1. 2. 3}. 4} flatten -> raises error because of a dnu on 4
>>
>> Anyone knows the right method which would work for my case?
>>
>> --
>> Simon Denier
>>
>>
>>
>
> --
> Simon Denier
>
>
>
>
> _______________________________________________
> Moose-dev mailing list
> [hidden email]
> https://www.iam.unibe.ch/mailman/listinfo/moose-dev

--
www.tudorgirba.com

"Don't give to get. Just give."






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