What is the rationale behind enabling Nullable!T to be used as a regular T?
Paul Backus
snarwin at gmail.com
Fri Feb 14 20:24:17 UTC 2020
On Friday, 14 February 2020 at 17:04:28 UTC, Adnan wrote:
> On Friday, 14 February 2020 at 14:43:22 UTC, Petar Kirov
> [ZombineDev] wrote:
>> On Friday, 14 February 2020 at 08:54:41 UTC, Adnan wrote:
>> The two ends of the design spectrum (as I see it) are:
>> 1. `Optional(T) x` as a range of [0,1] elements of type `T`.
>> For all possible operations `op` on type `T` there exists an
>> operation `Option(T).op` and the effect of executing is
>> equivalent to `x.map!fun`. This is what aliak's optional
>> package provides.
>
> Very interesting. I always thought that Option<T> is a
> type-guard for enforced null checks (I could be wrong here).
> But seems to me that this design circles back to square 1:
> having the callee remember to check if the length of the range
> is 0 or 1. Which is essentially similar to check sentinel
> values (i.e. check if the binarysearch returns -1 as index).
> What languages do this?
>
> What does Aliak's package provide that's fundamentally
> different to just returning a T[]? Empty T[] would mean `None`
> and a T[] with 1 item means `Some(T)`?
Aliak's package offers several features in addition to the range
interface that make it more convenient to work with than a simple
array. You can see a list in the README:
https://github.com/aliak00/optional/blob/v1.0.0/README.md#features
More information about the Digitalmars-d
mailing list