sum_types_generator 0.1.5+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 79

Build Status sum_types version sum_types_generator version

sum_types and sum_types_generator #

sum_types and sum_types_generator packages together define a code generator enabling sum-types in Dart.

Example #

In example/lib/src/ you can find a few sum-type declarations and the code generated for them.

This one models the natural numbers (with zero):

@SumType([
  Case<void>(name: "zero"),
  Case<_Nat>(name: "next"),
])
mixin _Nat implements _NatBase {
  Nat operator +(Nat other) => iswitch(
        zero: () => other,
        next: (next) => Nat.next(next + other),
      );

  int toInt() => iswitch(
        zero: () => 0,
        next: (next) => 1 + next.toInt(),
      );
}

Features #

Core:

  • [x] Const case-constructors (const Nat.zero())
  • [x] Extensible sum-types (Nat.toInt())
  • [x] Nested sum-types
  • [x] Recursive sum-types (Case<_Nat>(name: "next")Nat.next(Nat.zero()))
  • [x] Generic sum-types (Either<Left, Right>)
  • [x] Exhaustive in-line iswitch
  • [x] Inexhaustive in-line iswitcho (with otherwise: case)

Sugar:

  • [x] No-payload cases (Case<void>(name: "zero")Nat.zero())
  • [x] Default case-names (Case<String>()JSON.string("some"))

Trivia:

  • [x] Equality test
  • [x] Hash function
  • [x] To string conversion

Serialization-deserialization support through product-types interoperability:

  • [x] Deserialization support (NatRecord<Self>, Nat.load<T extends NatRecord<T>>(T rec))
  • [x] Serialization support (Nat.dump<T>(T Function({Unit zero, T next} make)))

Development #

Find the upcoming development plans in the project planner.

0.1.5+1 #

  • Update README.md.

0.1.5 #

  • Support generic sum-types.
  • Restructure the example project.

0.1.4 #

  • Allow nesting sum-types (by mentioning anchors).
  • Stop using dynamic and Null as empty-case markers, use only void.

0.1.3 #

  • Support serialization-deserialization of the generated sum-types through interoperability with user-defined product-types (XRecordBase<Self>, X.dump(·), X.load(·))

0.1.2+4 #

  • Update README.md and the package description.

0.1.2+3 #

  • Attempt to not publish uncommited changes.

0.1.2+2 #

  • Extend README.md.
  • Include analysis_options.yaml.

0.1.2+1 #

  • Relax dependency constraints to improve compatibility.

0.1.2 #

  • Integrate an example into the package.

0.1.1 #

  • Include a change-log file.

0.1.0 #

  • Define the annotations for sum_types_generator.
  • Include Unit type, required by the generator.

example/README.md

Example #

A sum_types and sum_types_generator packages usage example.

Running #

With Dart SDK #

As usual, run pub get first, then pub run example:main.

With Flutter SDK #

As usual, run flutter pub get first, then flutter pub run example:main.

Use this package as a library

1. Depend on it

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


dependencies:
  sum_types_generator: ^0.1.5+1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:sum_types_generator/sum_types_generator.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
58
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]
79
Learn more about scoring.

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

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: other

Primary library: package:sum_types_generator/sum_types_generator.dart with components: io, build, mirrors.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.4.0 <3.0.0
analyzer >=0.36.4 <0.39.0 0.38.5
build ^1.1.0 1.2.0
meta ^1.1.0 1.1.7
source_gen ^0.9.2 0.9.4+5
sum_types ^0.1.0 0.1.5+1
Transitive dependencies
args 1.5.2
async 2.4.0
charcode 1.1.2
collection 1.14.12
convert 2.1.1
crypto 2.1.3
csslib 0.16.1
dart_style 1.3.1
front_end 0.1.27
glob 1.1.7
html 0.14.0+3
kernel 0.3.27
logging 0.11.3+2
package_config 1.1.0
path 1.6.4
pedantic 1.8.0+1
pub_semver 1.4.2
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+12
yaml 2.2.0
Dev dependencies
dependency_validator any