Re: joiner: How to iterate over immutable ranges?

2016-02-15 Thread Bastiaan Veelo via Digitalmars-d-learn
On Monday, 15 February 2016 at 18:13:48 UTC, Ali Çehreli wrote: On 02/15/2016 06:25 AM, Bastiaan Veelo wrote: > I didn't even know about save... Its documentation is hidden > quite > well, because I still cannot find it. Heh. :) It is a part of the ForwardRange interface (more correctly, "co

Re: joiner: How to iterate over immutable ranges?

2016-02-15 Thread Ali Çehreli via Digitalmars-d-learn
On 02/15/2016 06:25 AM, Bastiaan Veelo wrote: > I didn't even know about save... Its documentation is hidden quite > well, because I still cannot find it. Heh. :) It is a part of the ForwardRange interface (more correctly, "concept"?). It looks like "the additional capability that one can save

Re: joiner: How to iterate over immutable ranges?

2016-02-15 Thread Bastiaan Veelo via Digitalmars-d-learn
On Monday, 15 February 2016 at 01:42:30 UTC, Mike Parker wrote: On Sunday, 14 February 2016 at 19:32:31 UTC, Bastiaan Veelo wrote: Maybe this [1] will help shed some light. [1] https://www.packtpub.com/books/content/understanding-ranges Good idea. I have your book, but it is very nice to hav

Re: joiner: How to iterate over immutable ranges?

2016-02-15 Thread Bastiaan Veelo via Digitalmars-d-learn
On Monday, 15 February 2016 at 01:14:10 UTC, Ali Çehreli wrote: On 02/14/2016 11:32 AM, Bastiaan Veelo wrote: If it's acceptable for you, the following code calls .save on the elements and it works: import std.algorithm.iteration; import std.stdio; import std.array;// <-- ADDED void main

Re: joiner: How to iterate over immutable ranges?

2016-02-14 Thread Mike Parker via Digitalmars-d-learn
On Sunday, 14 February 2016 at 19:32:31 UTC, Bastiaan Veelo wrote: Thanks. I didn't know that iterating a range means mutating its contents. I still don't quite get it, and it is probably because I don't fully understand ranges. I think what confuses me the most is their analogy to containers.

Re: joiner: How to iterate over immutable ranges?

2016-02-14 Thread Ali Çehreli via Digitalmars-d-learn
On 02/14/2016 11:32 AM, Bastiaan Veelo wrote: > Thanks. I didn't know that iterating a range means mutating its > contents. That's not the case: Just like an iterator, a range must maintain some state to know which item is next. What needs to be mutated is that iteration state. > I still don

Re: joiner: How to iterate over immutable ranges?

2016-02-14 Thread Bastiaan Veelo via Digitalmars-d-learn
On Sunday, 14 February 2016 at 18:28:11 UTC, Jonathan M Davis wrote: An immutable range fundamentally does not work. The same goes with const. In fact, a type that's immutable is going to fail isInputRange precisely because it can't possibly function as one. While empty and front may be calla

Re: joiner: How to iterate over immutable ranges?

2016-02-14 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, February 14, 2016 15:24:39 Bastiaan Veelo via Digitalmars-d-learn wrote: > Hi, > > I am having trouble getting the iteration methods in > std.algorithm.iteration to work on immutable data: > > > import std.algorithm.iteration; > > import std.stdio; > > > > void main() > > { > > stri

joiner: How to iterate over immutable ranges?

2016-02-14 Thread Bastiaan Veelo via Digitalmars-d-learn
Hi, I am having trouble getting the iteration methods in std.algorithm.iteration to work on immutable data: import std.algorithm.iteration; import std.stdio; void main() { string[][] cycles; cycles ~= ["one", "two"]; cycles ~= ["three", "four"]; foreach (numbe