www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - Optional 0.15.0 now compatible with vibe-d, safe, nogc, betterC.

reply aliak <something something.com> writes:
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
Jun 04
parent Marco de Wild <mdwild sogyo.nl> writes:
On Tuesday, 4 June 2019 at 07:22:34 UTC, aliak wrote:
 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])
Thanks! I've recently ran into the vibe-d serialization as well. It's awesome to be able to use Optional there.
Jun 04