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
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 reply Philippe Sigaud <philippe.sigaud gmail.com> writes:
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.
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
May 06 2010
next sibling parent reply 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.
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!
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
parent Philippe Sigaud <philippe.sigaud gmail.com> writes:
 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!
Fills, I'm not sure, but at least it's useful for me to digest both 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
May 06 2010
prev sibling next sibling parent reply 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.
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
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
parent reply 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.
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
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
parent Philippe Sigaud <philippe.sigaud gmail.com> writes:
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
Then you know as much as me. I don't even compile them into a library, I 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
May 06 2010
prev sibling 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.
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 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