some 1.2.2 some: ^1.2.2 copied to clipboard
Some / Maybe / Option / Result / Nullable, like Haskel Maybe, Can avoid semantic confusion caused by returning null when returning a value
Some / Maybe / Option / Result / Nullable #
Can avoid semantic confusion caused by returning null when returning a value
like Haskel Maybe
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');