Some / Maybe / Option / Result / Nullable

Can avoid semantic confusion caused by returning null when returning a value

like Haskel Maybe


pub MIT


Usage

Import

import 'package:some/index.dart'; // import all

import 'package:some/maybe.dart'; // only class Maybe
import 'package:some/some.dart'; // only class Some
import 'package:some/none.dart'; // only class None

import 'package:some/null.dart'; // only no null function

Create

Maybe<int> some = Some(1);
Maybe<int> none = None();
Maybe<int> some = Maybe(1);
Maybe<int> some = Maybe.Some(1);
Maybe<int> none = Maybe.None();

GetValue

if(some.has) {
    some.val
}

Pattern matching

if(some is Some) {}
if(some is Some<int>) {}
if(some is None) {}
some.when(some: (v) => 'some', none: () => 'none');
some.some((v) => 'some');
none.none(() => 'none');
none.defaultVal('none');
none.defaultValFn(() => 'none');

Libraries

index
maybe
none
null
some