Description

Provides a Maybe-like data type and helpers.

Package Information

Version0.0.1 (2014-May-25)
Repository https://github.com/dkhasel/maybe-d
LicenseMIT
CopyrightCopyright © 2014, Damon Khasel
Authorsdkhasel
Registered byDamon Khasel
Dependencies none

Installation

To use this package, put the following dependency into your project's dependencies section:

dub.json
dub.sdl

Readme

maybe-d

Simple syntactic sugar for a Maybe-like experience. Maybe(T) is just one small step toward a world without null.

Example usage:


import maybe.d;

Maybe!string maybeReturnsString( bool shouldReturnString )
{
    if( shouldReturnString )
    {
        return just!string("foo");
    }
    else
    {
        return nothing!string;
    }
}

// prints "the string is foo"
writeln( "the string is " ~ maybeReturnsString(true).getOrElse("bar") );

// prints "the string is bar"
writeln( "the string is " ~ maybeReturnsString(false).getOrElse("bar") );

Available versions

0.0.1 ~master