is there a name/function for this task, similar to expand

64 views
Skip to first unread message

Daniel Davidson

unread,
Mar 28, 2015, 11:17:44 AM3/28/15
to mi...@dartlang.org
I see expand does: 

    print([[1, 2, 3], ['a', 'b']].expand((i) => i))

which gives:
    (1, 2, 3, a, b)

I want to throw in a function on the list:

    print(???[1, 2, [3, 4, [5, 6]], 7].???)

to give Iterable:

    (1, 2, 3, 4, 5, 6, 7)


Thanks,
Dan


Lasse R.H. Nielsen

unread,
Mar 28, 2015, 3:21:06 PM3/28/15
to mi...@dartlang.org
Seems like you want a "deep flatten".

A naive implementation could be:

flatten(iterable) => iterable.expand((v) => v is Iterable ? flatten(v) : [v]);

/L

--
For other discussions, see https://groups.google.com/a/dartlang.org/
 
For HOWTO questions, visit http://stackoverflow.com/tags/dart
 
To file a bug report or feature request, go to http://www.dartbug.com/new

To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.



--
Lasse R.H. Nielsen - l...@google.com  
'Faith without judgement merely degrades the spirit divine'
Google Denmark ApS - Frederiksborggade 20B, 1 sal - 1360 København K - Denmark - CVR nr. 28 86 69 84

Daniel Davidson

unread,
Mar 28, 2015, 3:49:23 PM3/28/15
to mi...@dartlang.org
Great, thanks! I'll use that for now.
Is this something that is generally useful and maybe worthy of quiver.iterables?

Thanks,
Dan
Reply all
Reply to author
Forward
0 new messages