Flatten range of ranges

new to d a at a.com
Thu May 6 11:50:24 PDT 2010


Philippe Sigaud Wrote:

> On Thu, May 6, 2010 at 18:24, Ali Çehreli <acehreli at yahoo.com> wrote:
> 
> > Ali Çehreli wrote:
> >
> >> new to d wrote:
> >>
> >>> Is there any function in phobos that does something like that:
> >>>
> >>> auto a = [[1,2],[3,4]];
> >>> assert(equals(flatten(a), [1,2,3,4]));
> >>>
> >>> I am just learning D and ca't find anything like that in the docs.
> >>>
> >>
> I've this in a dsource project:
> 
> http://svn.dsource.org/projects/dranges/trunk/docs/range2.html
> (look for flatten or concat). It's a lazy range. Flatten depends on a
> template for wrapping code, present in the traits2 module.
> 
> http://www.dsource.org/projects/dranges/browser/trunk/range2.d
> http://www.dsource.org/projects/dranges/browser/trunk/traits2.d
> 
> Hmm, this is waiting for quite an update. I've lots of thing for
> producing/mapping/filtering... ranges of ranges while conserving their
> topology/rank.
> If you find anything useful for you in this project, tell me!
> 
> 
> Philippe
> 
> <br><br><div class="gmail_quote">On Thu, May 6, 2010 at 18:24, Ali Çehreli <span dir="ltr">&lt;<a href="mailto:acehreli at yahoo.com">acehreli at yahoo.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
> <div><div></div><div class="h5">Ali Çehreli wrote:<br>
> <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
> new to d wrote:<br>
> <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
> Is there any function in phobos that does something like that:<br>
> <br>
> auto a = [[1,2],[3,4]];<br>
> assert(equals(flatten(a), [1,2,3,4]));<br>
> <br>
> I am just learning D and ca't find anything like that in the docs.<br></blockquote></blockquote></div></div></blockquote><div><br>I've this in a dsource project:<br><br><a href="http://svn.dsource.org/projects/dranges/trunk/docs/range2.html">http://svn.dsource.org/projects/dranges/trunk/docs/range2.html</a> <br>
> </div></div>(look for flatten or concat). It's a lazy range. Flatten depends on a template for wrapping code, present in the traits2 module.<br><br><a href="http://www.dsource.org/projects/dranges/browser/trunk/range2.d">http://www.dsource.org/projects/dranges/browser/trunk/range2.d</a><br>
> <a href="http://www.dsource.org/projects/dranges/browser/trunk/traits2.d">http://www.dsource.org/projects/dranges/browser/trunk/traits2.d</a><br><br>Hmm, this is waiting for quite an update. I've lots of thing for producing/mapping/filtering... ranges of ranges while conserving their topology/rank.<br>
> If you find anything useful for you in this project, tell me!<br><br><br>Philippe<br><br>
> 

concat() in range2 seems to do exactly what i wanted, thank you.  I think something like that should be included in the standard library since it's a pretty basic operation. I haven't taken a good look at the other stuff in range2 yet.


More information about the Digitalmars-d-learn mailing list