Motive behind !empty() with front() instead of Optional front()
Jacob Carlborg
doob at me.com
Wed Mar 31 07:27:18 UTC 2021
On 2021-03-24 20:23, Per Nordlöw wrote:
> What's the motive behinds D's range design choice of needing
>
> if (!empty)
> {
> // use front or back
> }
>
> instead of having front returning an optional/maybe type with enforced
> pattern matching?
In my opinion, the best way to interact with an Optional type is not to
use pattern matching but to use algorithms like `map`, `each` and so on.
That means an Optional type needs to implement the range API. Might be a
bit confusioning if `front` then returns an Optional.
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list