www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Flatten range of ranges

reply new to d <a a.com> writes:
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.
May 06 2010
parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
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.

How about chain: http://digitalmars.com/d/2.0/phobos/std_range.html#chain Ali
May 06 2010
next sibling parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
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.

How about chain: http://digitalmars.com/d/2.0/phobos/std_range.html#chain

Sorry, of course that's not what you wanted... :( Ali
May 06 2010
parent new to d <a a.com> writes:
Philippe Sigaud Wrote:

 On Thu, May 6, 2010 at 18:24, Ali «ehreli <acehreli 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.



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 yahoo.com">acehreli 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/ ocs/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/trait 2.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.
May 06 2010
prev sibling next sibling parent Philippe Sigaud <philippe.sigaud gmail.com> writes:
--00032555e4be5ae9c00485efe3c7
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On Thu, May 6, 2010 at 18:24, Ali =C7ehreli <acehreli yahoo.com> wrote:

 Ali =C7ehreli wrote:

 new to d wrote:

 Is there any function in phobos that does something like that:

 auto a =3D [[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.



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 --00032555e4be5ae9c00485efe3c7 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <br><br><div class=3D"gmail_quote">On Thu, May 6, 2010 at 18:24, Ali =C7ehr= eli <span dir=3D"ltr">&lt;<a href=3D"mailto:acehreli yahoo.com">acehreli ya= hoo.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D= "margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padd= ing-left: 1ex;"> <div><div></div><div class=3D"h5">Ali =C7ehreli wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin: 0pt 0pt 0pt 0.8ex; borde= r-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"> new to d wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin: 0pt 0pt 0pt 0.8ex; borde= r-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 =3D [[1,2],[3,4]];<br> assert(equals(flatten(a), [1,2,3,4]));<br> <br> I am just learning D and ca&#39;t find anything like that in the docs.<br><= /blockquote></blockquote></div></div></blockquote><div><br>I&#39;ve this in= a dsource project:<br><br><a href=3D"http://svn.dsource.org/projects/drang= es/trunk/docs/range2.html">http://svn.dsource.org/projects/dranges/trunk/do= cs/range2.html</a> <br> </div></div>(look for flatten or concat). It&#39;s a lazy range. Flatten de= pends on a template for wrapping code, present in the traits2 module.<br><b= r><a href=3D"http://www.dsource.org/projects/dranges/browser/trunk/range2.d= ">http://www.dsource.org/projects/dranges/browser/trunk/range2.d</a><br> <a href=3D"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&#39;ve lots of thing for produ=

rank.<br> If you find anything useful for you in this project, tell me!<br><br><br>Ph= ilippe<br><br> --00032555e4be5ae9c00485efe3c7--
May 06 2010
prev sibling next sibling parent Graham Fawcett <fawcett uwindsor.ca> writes:
On Thu, 06 May 2010 19:01:04 +0200, Philippe Sigaud wrote:

 On Thu, May 6, 2010 at 18:24, Ali Çehreli <acehreli 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.



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!

These are great! Thank you. Coming from some of the languages that you cite as inspirations, I found the limited set of range HOFs in D2 to be really unfortunate. Your project fills the gap! Best, Graham
May 06 2010
prev sibling next sibling parent Graham Fawcett <fawcett uwindsor.ca> writes:
On Thu, 06 May 2010 19:01:04 +0200, Philippe Sigaud wrote:

 On Thu, May 6, 2010 at 18:24, Ali Çehreli <acehreli 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.



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

Newbie setup question: I'm interested in trying out dranges. What's the best way for me to "install" dranges, so that my test code can reference range2 and the other drange modules? Thanks, Graham
May 06 2010
prev sibling next sibling parent Philippe Sigaud <philippe.sigaud gmail.com> writes:
--00032555e4be071a8f0485f040ff
Content-Type: text/plain; charset=ISO-8859-1

 These are great! Thank you. Coming from some of the languages that you
 cite as inspirations, I found the limited set of range HOFs in D2 to be
 really unfortunate. Your project fills the gap!

clojure/Haskell (got rid of Scala) and D :-) If you find any pb, don't hesitate to send me some mail, because I really discover these functions as I go forward... Philippe --00032555e4be071a8f0485f040ff Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <br> <div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margi= n: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-le= ft: 1ex;">These are great! Thank you. Coming from some of the languages tha= t you<br> cite as inspirations, I found the limited set of range HOFs in D2 to be<br> really unfortunate. Your project fills the gap!<br><br></blockquote><div><b= r>Fills, I&#39;m not sure, but at least it&#39;s useful for me to digest bo= th clojure/Haskell (got rid of Scala) and D :-)<br>If you find any pb, don&= #39;t hesitate to send me some mail, because I really discover these functi= ons as I go forward...<br> <br><br>Philippe <br></div></div> --00032555e4be071a8f0485f040ff--
May 06 2010
prev sibling next sibling parent Graham Fawcett <fawcett uwindsor.ca> writes:
On Thu, 06 May 2010 17:25:44 +0000, Graham Fawcett wrote:

 On Thu, 06 May 2010 19:01:04 +0200, Philippe Sigaud wrote:
 
 On Thu, May 6, 2010 at 18:24, Ali Çehreli <acehreli 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.



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

Newbie setup question: I'm interested in trying out dranges. What's the best way for me to "install" dranges, so that my test code can reference range2 and the other drange modules?

I should clarify that I know I can just put the dranges sources in, e.g, a 'dranges' subdirectory, compile drange/*.d into a library and do something like: dmd -Ldranges/dranges.a -Idranges test.d ...and I could modify /etc/dmd.conf by hand to add my dranges directory to the appropriate paths. But I wonder if I'm missing a more idiomatic way to install third-party libraries for D2. Thanks, Graham
May 06 2010
prev sibling parent Philippe Sigaud <philippe.sigaud gmail.com> writes:
--00032555610eb004ee0485f3f8db
Content-Type: text/plain; charset=ISO-8859-1

Graham:
I should clarify that I know I can just put the dranges sources in, e.g,

 a 'dranges' subdirectory, compile drange/*.d into a library and do
 something like:

 dmd -Ldranges/dranges.a -Idranges test.d

 ...and I could modify /etc/dmd.conf by hand to add my dranges directory
 to the appropriate paths. But I wonder if I'm missing a more idiomatic
 way to install third-party libraries for D2.

 Thanks,
 Graham

just add them into my current project (Code::Blocks accepts this) and compile the entire project. I just put a zip file in the download area with some new modules and all the modules inside a dranges directory. What I'd do is just putting the dranges dir inside my project and do import dranges.all; in my own module. It seems in this case you don't even need to indicate any path or whatever. " module mymod; import dranges.all; void main() {} " % dmd mymod (untested, I use DMD under windows and am on Linux right now, but IIRC it worked for me.) Philippe --00032555610eb004ee0485f3f8db Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Graham:<br>&gt;I should clarify that I know I can just put the dranges sour= ces in, e.g,<br><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote= " style=3D"margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, = 204); padding-left: 1ex;"> a &#39;dranges&#39; subdirectory, compile drange/*.d into a library and do<= br> something like:<br> <br> dmd -Ldranges/dranges.a -Idranges test.d<br> <br> ...and I could modify /etc/dmd.conf by hand to add my dranges directory<br> to the appropriate paths. But I wonder if I&#39;m missing a more idiomatic<= br> way to install third-party libraries for D2.<br> <br> Thanks,<br> <font color=3D"#888888">Graham<br> <br></font></blockquote><div><br>Then you know as much as me. I don&#39;t e= ven compile them into a library, I just add them into my current project (C= ode::Blocks accepts this) and compile the entire project.<br><br>I just put= a zip file in the download area with some new modules and all the modules = inside a dranges directory.<br> What I&#39;d do is just putting the dranges dir inside my project and do<br=
<br>import dranges.all;<br><br>in my own module. It seems in this case you=

mymod;<br> import dranges.all;<br><br>void main() {}<br>&quot;<br><br>% dmd mymod<br><= br>(untested, I use DMD under windows and am on Linux right now, but IIRC i= t worked for me.)<br><br>Philippe<br><br></div></div> --00032555610eb004ee0485f3f8db--
May 06 2010