opNext: Simplified ranges
Joseph Rushton Wakeling
joseph.wakeling at webdrake.net
Sat Nov 5 09:38:36 UTC 2022
On Saturday, 5 November 2022 at 06:01:54 UTC, Tomer at Weka wrote:
> ```
> bool opNext(out T elem) {...}
> ```
>
> `opNext` returns true if it "produced" an element, false if it
> reached the end.
Out of curiosity: what do you think are the pros and cons of this
versus, say, something like:
```
Option!(T) opNext() { ... }
```
Where `Option` is an implementation of the option type, and hence
encapsulates the question of whether an element was produced or
not? (IIRC this has been another suggestion for a
simplified/redesigned range concept.)
An `Option`-based design has the advantage of not requiring a
persistent `front`, which may fit better with true input ranges
(e.g. reading from a stream). OTOH it may make things more
clunky for the case where there is persistent underlying data
that a `front` method could refer to.
More information about the Digitalmars-d
mailing list