My two cents
H. S. Teoh
hsteoh at quickfur.ath.cx
Fri Oct 20 18:56:53 UTC 2017
On Fri, Oct 20, 2017 at 06:20:52PM +0000, Random D user via Digitalmars-d wrote:
> On Friday, 20 October 2017 at 02:20:31 UTC, Adam D. Ruppe wrote:
> > On Friday, 20 October 2017 at 00:26:19 UTC, bauss wrote:
> > > return foo ?? null; would be so much easier.
> > return getOr(foo, null);
>
> I guess with UFCS you could get:
> return foo.PP(null); // vs.
> return foo ?? null;
>
> :D
You could have this today via a nicely-named UFCS function:
T orElse(T t, lazy T defaultVal) { return t is null ? defaultVal : t; }
class C {}
C defaultC;
C makeC() { ... }
auto c = makeC().orElse(defaultC);
You can even UFCS-chain it:
auto c = makeC().orElse(makeCAnotherWay())
.orElse(makeCYetAnotherWay())
.orElse(defaultC);
T
--
Stop staring at me like that! It's offens... no, you'll hurt your eyes!
More information about the Digitalmars-d
mailing list