Project Elvis
Meta
jared771 at gmail.com
Mon Nov 6 20:14:17 UTC 2017
On Monday, 6 November 2017 at 19:55:13 UTC, Jacob Carlborg wrote:
> On 2017-11-06 20:40, Dmitry Olshansky wrote:
>
>> I’d argue this NOT what we want. Nullability is best captured
>> in the typesystem even if in the form of Nullable!T.
>
> Yeah, it would be better if the elvis operator good integrate
> with a nullable/option type as well in addition to null.
What's the point when we can already do it easily in a library,
and arguably with better ergonomics?
(http://forum.dlang.org/post/fshlmahxfaeqtwjbjouz@forum.dlang.org)
auto tree = new Node(1,
new Node(2),
new Node(3,
null,
new Node(4)
)
);
import std.stdio;
writeln(safeDeref(tree).right.right.val.orElse(-1));
writeln(safeDeref(tree).left.right.left.right.orElse(null));
writeln(safeDeref(tree).left.right.left.right.val.orElse(-1));
vs.
writeln(tree?. right?.right?.val ?: -1);
writeln(tree?.left?.right?.left?.right);
writeln(tree?.left?.right?.left?.right?.val ?: -1);
The functionality is probably a good idea, but a library solution
is doable today without any acrobatics.
More information about the Digitalmars-d
mailing list