some 1.3.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 50

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');

1.3.0 #

now

  • Some(1) != 1
  • None() == None()

1.2.4 #

Fix lib/src/maybe.dart. (-0.50 points)
Analysis of lib/src/maybe.dart reported 1 hint:
line 28 col 28: Avoid types as parameter names.

Fix lib/src/none.dart. (-0.50 points)
Analysis of lib/src/none.dart reported 1 hint:
line 18 col 28: Avoid types as parameter names.

Fix lib/src/null.dart. (-0.50 points)
Analysis of lib/src/null.dart reported 1 hint:
line 12 col 44: Avoid types as parameter names.

1.2.3 #

Rewritten implementation

Fix bug: eq

  • Some(1) != 1

now

  • Some(1) == 1

Add eq test

1.2.2 #

remove const None
Fix bug: const None

1.2.1 #

Fix bug(null.dart): defaultVal and defaultValFn when Some while return None

1.2.0 #

Fix bug: defaultVal and defaultValFn when Some while return None

1.1.1 #

const None

1.1.0 #

Add const constructor

1.0.1 #

Add example

1.0.0 #

Create this

example/example.md

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');

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  some: ^1.3.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:some/some.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

We analyzed this package on Dec 9, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.1
  • pana: 0.12.21

Health suggestions

Format lib/index.dart.

Run dartfmt to format lib/index.dart.

Format lib/maybe.dart.

Run dartfmt to format lib/maybe.dart.

Format lib/none.dart.

Run dartfmt to format lib/none.dart.

Format lib/null.dart.

Run dartfmt to format lib/null.dart.

Format lib/some.dart.

Run dartfmt to format lib/some.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
test ^1.6.5