Optional<T> equivalent in D?

Brad Anderson eco at gnuk.net
Fri Nov 15 14:42:41 PST 2013


On Friday, 15 November 2013 at 22:41:40 UTC, Brad Anderson wrote:
> On Friday, 15 November 2013 at 22:39:40 UTC, Jacek 
> Furmankiewicz wrote:
>> Many other languages are starting to frown on returning null 
>> values from methods (due to NullPointerException risks, etc) 
>> and wrapping them instead in an Optional<T> like in
>>
>> Scala:
>> http://blog.danielwellman.com/2008/03/using-scalas-op.html
>>
>> Google Guava for Java: (now rolled into the base JDK for Java 
>> 8):
>> https://code.google.com/p/guava-libraries/wiki/UsingAndAvoidingNullExplained
>>
>> Is there a similar approach in D? Or maybe an equivalent is in 
>> a commonly used external library?
>
> Sounds like std.typecons.Nullable to me.

I recommend having a look around std.typecons while you are in 
there.  It's got a lot of gems that seem to go unnoticed by a lot 
of people.


More information about the Digitalmars-d-learn mailing list