Re: InputRange for data structure without order?

2025-06-04 Thread Andy Valencia via Digitalmars-d-learn
On Tuesday, 3 June 2025 at 16:03:15 UTC, Andy Valencia wrote: I have a situation where chain()'ing them together would be convenient, but InputRange requires front() and popFront(). As an exercise in chaining opApply based containers, I tried: ```d // Chain across containers; their type is T a

Re: InputRange for data structure without order?

2025-06-04 Thread monkyyy via Digitalmars-d-learn
On Wednesday, 4 June 2025 at 20:34:30 UTC, Ali Çehreli wrote: generators My mental model of slices differ > I > think the some of the rng primitives also just mutate. Nullable is a > range for some God-Forsaken reason, it would have to mutate data. I wasn't aware of that. I wonder whether someo

Re: InputRange for data structure without order?

2025-06-04 Thread Ali Çehreli via Digitalmars-d-learn
On 6/4/25 12:53 PM, monkyyy wrote: > Iota should mutate the underlining data and does. There is no underlying data for some ranges like iota because they are generators. Yes, it's a complication that D uses the term "range" for generators as well. > Unjustifiably slices > are in the weird li

Re: InputRange for data structure without order?

2025-06-04 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 04, 2025 at 12:00:57PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 6/4/25 4:10 AM, Monkyyy wrote: > > On Wednesday, 4 June 2025 at 02:11:18 UTC, H. S. Teoh wrote: > >> . But in general, containers should NOT be conflated with ranges. > >> That only leads to wrong design. > >

Re: InputRange for data structure without order?

2025-06-04 Thread Ali Çehreli via Digitalmars-d-learn
On 6/4/25 4:10 AM, Monkyyy wrote: > On Wednesday, 4 June 2025 at 02:11:18 UTC, H. S. Teoh wrote: >> . But in general, containers should NOT be conflated with ranges. That >> only leads to wrong design. >> >> range should NOT mutate the container. It should be regarded as >> something separate fro

Re: InputRange for data structure without order?

2025-06-04 Thread Andy Valencia via Digitalmars-d-learn
On Wednesday, 4 June 2025 at 10:47:24 UTC, Jonathan M Davis wrote: Typically, a container will implement opSlice (or opIndex, since confusingly, both can be used in this case) and have it return a range over the container. So, then you can do auto range = myContainer[]; ... Brilliant, th

Re: InputRange for data structure without order?

2025-06-04 Thread Monkyyy via Digitalmars-d-learn
On Wednesday, 4 June 2025 at 02:11:18 UTC, H. S. Teoh wrote: . But in general, containers should NOT be conflated with ranges. That only leads to wrong design. range should NOT mutate the container. It should be regarded as something separate from the container. Not "general". It's a safety

Re: InputRange for data structure without order?

2025-06-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, June 3, 2025 9:39:35 PM Mountain Daylight Time Andy Valencia via Digitalmars-d-learn wrote: > On Wednesday, 4 June 2025 at 02:11:18 UTC, H. S. Teoh wrote: > > The correct way to do this is to create a method in the > > container that returns a range over its contents. Popping the > >