Re: Why is there no range iteration with index by the language?

2020-06-10 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 10 June 2020 at 00:53:30 UTC, Seb wrote: [snip] Anyhow, I would be highly in favor of DMD doing this. It's one of those many things that I have on my list for D3 or a D fork. Chapel supports zippered iteration [1]. From the discussion here, it sounds very much like the

Re: Why is there no range iteration with index by the language?

2020-06-10 Thread Dukc via Digitalmars-d-learn
On Wednesday, 10 June 2020 at 15:34:57 UTC, Steven Schveighoffer wrote: My biggest problem with enumerate is that you can't bind the tuple to parameters for something like map: arr.enumerate.map!((idx, val) => ...) doesn't work. Instead you have to do: arr.enumerate.map!((tup) => ...) And

Re: Why is there no range iteration with index by the language?

2020-06-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/9/20 7:53 PM, Q. Schroll wrote: Is there any particular reason why std.range : enumerate is a thing and     foreach (i, e; range) { ... } doesn't work from the get-go? I wouldn't have such an issue with it if static foreach would work with enumerate just fine. What is the use case for

Re: Why is there no range iteration with index by the language?

2020-06-10 Thread Jesse Phillips via Digitalmars-d-learn
On Tuesday, 9 June 2020 at 23:53:16 UTC, Q. Schroll wrote: Is there any particular reason why std.range : enumerate is a thing Someone already mentioned dictionary. Consider that most ranges don't actually have an index. In this case you aren't actually asking to add indexes, but a count of

Re: Why is there no range iteration with index by the language?

2020-06-09 Thread Seb via Digitalmars-d-learn
On Wednesday, 10 June 2020 at 01:35:32 UTC, Q. Schroll wrote: On Wednesday, 10 June 2020 at 00:53:30 UTC, Seb wrote: It's a bit more complicated though as you need to avoid subtle breakage with ranges that return tuples that are auto-expanded like e.g. `foreach (k,v; myDict)`. Okay, I can

Re: Why is there no range iteration with index by the language?

2020-06-09 Thread Q. Schroll via Digitalmars-d-learn
On Wednesday, 10 June 2020 at 00:53:30 UTC, Seb wrote: It's a bit more complicated though as you need to avoid subtle breakage with ranges that return tuples that are auto-expanded like e.g. `foreach (k,v; myDict)`. Okay, I can accept that. It's a poor decision, but well, it is what it is.

Re: Why is there no range iteration with index by the language?

2020-06-09 Thread Seb via Digitalmars-d-learn
On Tuesday, 9 June 2020 at 23:53:16 UTC, Q. Schroll wrote: Is there any particular reason why std.range : enumerate is a thing and foreach (i, e; range) { ... } doesn't work from the get-go? I wouldn't have such an issue with it if static foreach would work with enumerate just fine. As

Re: Why is there no range iteration with index by the language?

2020-06-09 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 9 June 2020 at 23:53:16 UTC, Q. Schroll wrote: Is there any particular reason why std.range : enumerate is a thing and [...] I don't think there is any particular reason. Other than that might shadow an opApply. And C++ iterators didn't have it.

Re: Why is there no range iteration with index by the language?

2020-06-09 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 09, 2020 at 05:03:55PM -0700, H. S. Teoh via Digitalmars-d-learn wrote: > On Tue, Jun 09, 2020 at 11:53:16PM +, Q. Schroll via Digitalmars-d-learn > wrote: > > Is there any particular reason why std.range : enumerate is a thing > > and > > > > foreach (i, e; range) { ... } >

Re: Why is there no range iteration with index by the language?

2020-06-09 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 09, 2020 at 11:53:16PM +, Q. Schroll via Digitalmars-d-learn wrote: > Is there any particular reason why std.range : enumerate is a thing > and > > foreach (i, e; range) { ... } > > doesn't work from the get-go? [...] std.range.indexed is your friend. ;-) T -- Let's eat