union_type 1.0.1

  • README.md
  • Installing
  • Versions
  • 59

union_type

version 1.0.0+1 build status

Dart union type library. This library no longer depends on dart:mirrors.

Usage

union_type provides helpers for type assertions across types that do not share ancestry.

import 'package:union_type/union_type.dart';
const UnionType BAZ = const UnionType('Baz', types: const [Foo, Bar]);

main() {
    BAZ.enforce(new Foo()); // No error
    BAZ.enforce(new Bar()); // No error
    BAZ.enforce({}); // TypeError
    BAZ.enforceAll([1, 2]); // TypeError
    
    if (BAZ.check(foo)) {
        // Do something
    } else {
        // Do something else
    }
}

Union types can assert other union types as well.

const UnionType MASTER =
    const UnionType('MasterType', types: const [BAZ, OtherType]);

You can also create a list of items, asserting that they match the type.

import 'package:union_type/union_type.dart';
const UnionType MONSTER =
    const UnionType('Monster', types: const [Franken, Stein]);

main() {
    var monsterArmy = new TypedList(MONSTER);

    monsterArmy.add(new Franken());
    monsterArmy.add(new Stein());

    for (var monster in monsterArmy) {
        print('MWAHAHAHA: $monster');
    }

    monsterArmy.add(2); // TypeError
    monsterArmy.addAll([2, 3, 4, '5']); // TypeError
}

Use this package as a library

1. Depend on it

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


dependencies:
  union_type: ^1.0.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:union_type/union_type.dart';
  
Version Uploaded Documentation Archive
1.0.1 Jul 15, 2017 Go to the documentation of union_type 1.0.1 Download union_type 1.0.1 archive
1.0.0+1 Dec 17, 2016 Go to the documentation of union_type 1.0.0+1 Download union_type 1.0.0+1 archive
1.0.0 Dec 17, 2016 Go to the documentation of union_type 1.0.0 Download union_type 1.0.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
29
Health:
Code health derived from static analysis. [more]
98
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
74
Overall:
Weighted score of the above. [more]
59
Learn more about scoring.

We analyzed this package on Aug 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.11.8

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:union_type/union_type.dart.

Issues and suggestions

Maintain CHANGELOG.md.

Changelog entries help clients to follow the progress in your code.

Package is getting outdated.

The package was released 55 weeks ago.

The description is too short.

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Maintain an example.

Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use union_type.dart.

Format lib/matchers.dart.

Run dartfmt to format lib/matchers.dart.

Format lib/union_type.dart.

Run dartfmt to format lib/union_type.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0
matcher ^0.12.0+2 0.12.4
Transitive dependencies
path 1.6.2
stack_trace 1.9.3
Dev dependencies
test ^0.12.17+3