Optional 0.15.0 now compatible with vibe-d, @safe, @nogc, betterC.

aliak something at something.com
Tue Jun 4 07:22:34 UTC 2019


Hey,

I've recently released optional 0.15.0 [0] that includes support 
for vibe-d serialization/deserialization. So you can use it 
instead of Nullable for types that may or may not be there (I got 
bit by Nullable again so felt this had to be added [1])

Also of note is that it can be used in nogc and safe code, and is 
compatible with betterC.

Extract from readme:

* Use pattern matching, orElse
   fun.match!(
     (int value) => writeln("it returns an int"),
     () => writeln("did not return anything"),
   );
   fun.orElse(3); // returns some(fun()) or some(3)

* Safely call functions on classes that are null or structs that 
don't exist
   class C { int fun() { return 3; } }
   Optional!C a = null;
   a.dispatch.fun; // no crash, returns no!int

* Forwards any operator calls to the wrapped typed only if it 
exists, else just returns a none
   Optional!int a = 3;
   Optional!int b = none;
   a + a; // evaluates to some(6);
   a + b; // evaluates to no!int;

* Compatible with std.algorithm and std.range
   fun.each!(value => writeln("I got the value"));
   fun.filter!"a % 2 == 0".each!(value => writeln("got even 
value"));

Cheers,
- Ali

[0] https://code.dlang.org/packages/optional
[1] 
https://forum.dlang.org/thread/thtjhrvlgetaahcamqrm@forum.dlang.org


More information about the Digitalmars-d-announce mailing list