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

outdated

No more null errors.

maybe #

Pub

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.when<T> method to access your potential value so you are forced to check its status before using it.

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

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

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

// ... but you can explictly activate null values
maybe = Maybe<String>.some(null, nullable: true);
Maybe.when(maybe, some: (v) {
    print(v); // called with null
});

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