maybe 0.1.0 copy "maybe: ^0.1.0" to clipboard
maybe: ^0.1.0 copied to clipboard

outdated

No more null errors.

maybe #

No more null check with an dart equivalent of Maybe (Haskel, Elm) / Option (F#).

Usage #

The key is that you need to call the Maybe.check<T> method to access your potential value and you are forced to check its status.

// Defining a value
var maybe = Maybe<String>.some("hello world");
Maybe.when<String>(maybe, some: (v) {
    print(v); // "hello world"
});

// Defining nothing
maybe = Maybe<String>.nothing();
Maybe.when<String>(maybe, some: (v) {
    print(v); // not called!
});

// You can add a default value when nothing
maybe = Maybe<String>.some(null);
Maybe.when<String>(maybe, some: (v) {
        print(v); // "hello world"
    }, 
    defaultValue: () => "hello world");

// By default, null as value is considered as nothing
maybe = Maybe<String>.some(null);
Maybe.when<String>(maybe, some: (v) {
    print(v); // not called!
});

// ... but you can explictly activate null values
maybe = Maybe<String>.some(null, nullable: true);
Maybe.when<String>(maybe, some: (v) {
    print(v); // not called!
});
0
likes
0
pub points
64%
popularity

Publisher

unverified uploader

No more null errors.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on maybe