Re: byChunk odd behavior?

2016-03-26 Thread Hanh via Digitalmars-d-learn
On Saturday, 26 March 2016 at 08:34:04 UTC, cym13 wrote: Sorry, it seems I completely misunderstood you goal. I thought that take() consumed its input (which mostly only shows that I really am careful about not reusing ranges). Writting a take that consume shouldn't be difficult though:

Re: byChunk odd behavior?

2016-03-25 Thread Hanh via Digitalmars-d-learn
On Friday, 25 March 2016 at 08:01:04 UTC, cym13 wrote: // This consume auto buffer3 = range.take(4).array; assert(buffer3 == [0, 5, 10, 15]); } Thanks for your help. However the last statement is incorrect. I am in fact looking for a version of 'take' that consumes

Re: byChunk odd behavior?

2016-03-24 Thread Hanh via Digitalmars-d-learn
On Wednesday, 23 March 2016 at 19:07:34 UTC, cym13 wrote: In Scala, 'take' consumes bytes from the iterator. So the same code would be buffer = range.take(N).toArray Then just do that! import std.range, std.array; auto buffer = range.take(N).array; auto example = iota(0, 200, 5)

Re: byChunk odd behavior?

2016-03-22 Thread Hanh via Digitalmars-d-learn
Thanks for your help everyone. I agree that the issue is due to the misusage of an InputRange but what is the semantics of 'take' when applied to an InputRange? It seems that calling it invalidates the range; in which case what is the recommended way to get a few bytes and keep on advancing.

Re: byChunk odd behavior?

2016-03-22 Thread Hanh via Digitalmars-d-learn
On Tuesday, 22 March 2016 at 07:17:41 UTC, Hanh wrote: Hi all, I'm trying to process a rather large file as an InputRange and run into something strange with byChunk / take. void test() { auto file = new File("test.txt"); auto input = file.byChunk(2).joiner; input.take

byChunk odd behavior?

2016-03-22 Thread Hanh via Digitalmars-d-learn
Hi all, I'm trying to process a rather large file as an InputRange and run into something strange with byChunk / take. void test() { auto file = new File("test.txt"); auto input = file.byChunk(2).joiner; input.take(3).array; foreach (char c; input) {

Auto field member?

2016-03-02 Thread Hanh via Digitalmars-d-learn
Hi, Is there a way to declare a class field 'auto'? I have a problem when I try to 'promote' a variable to a field. import std.csv; import std.typecons; class Test { this() { auto text = "Joe,Carpenter,30\nFred,Blacksmith,40\r\n"; auto reader = csv