sum_types 0.1.2 copy "sum_types: ^0.1.2" to clipboard
sum_types: ^0.1.2 copied to clipboard

outdated

Annotations for a code generator enabling sum-types in Dart.

example/lib/example.dart

import 'package:meta/meta.dart';
import 'package:sum_types/sum_types.dart';

part 'example.g.dart';

@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(),
      );
}

@SumType([
  Case<Map<String, _JSON>>(name: "object"),
  Case<List<_JSON>>(name: "array"),
  Case<String>(),
  Case<double>(name: "number"),
  Case<bool>(name: "boolean"),
  Case<void>(name: "empty"),
])
mixin _JSON {}
13
likes
0
pub points
75%
popularity

Publisher

unverified uploader

Annotations for a code generator enabling sum-types in Dart.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

meta

More

Packages that depend on sum_types