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

outdated

sum_types and sum_types_generator packages together define 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
76%
popularity

Publisher

unverified uploader

sum_types and sum_types_generator packages together define 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