some

Creator: coderz1093

Last updated:

0 purchases

TODO
Add to Cart

Description:

some

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
copied to clipboard
Create #
Maybe<int> some = Some(1);
copied to clipboard
Maybe<int> none = None();
copied to clipboard
Switch (dart > 3.0.0) #
Maybe<int> some = Some(1);

var a = switch (some) {
Some(v: var v) => v,
null => 0
};
copied to clipboard
Check has value #
some.isSome
none.isNone
some.has
copied to clipboard
Get value #
if(some.has) {
some.val!
}
copied to clipboard
Monadic #
some.map((v) => 'some');
some.then((v) => 'some');
copied to clipboard
some.flatMap((v) => Some('some'));
some.andThen((v) => Some('some'));
copied to clipboard
Logical #
some.and(Some('some'));
some.andThen((v) => Some('some'));
copied to clipboard
some.or(Some('some'));
some.orElse(() => Some('some'));
copied to clipboard
some.xor(Some('some'));
copied to clipboard
Flatten #
someSome.flatten();
copied to clipboard
Pattern matching #
some.when(some: (v) => 'some', none: () => 'none');
copied to clipboard
some.some((v) => 'some');
copied to clipboard
none.none(() => 'none');
copied to clipboard
none.defaultVal('none');
copied to clipboard
none.defaultValFn(() => 'none');
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.