algebraic_types 0.0.2 copy "algebraic_types: ^0.0.2" to clipboard
algebraic_types: ^0.0.2 copied to clipboard

Dart macros for algebraic types

alegbraic_types #

https://github.com/dart-lang/language/blob/main/working/macros/feature-specification.md

dart run --enable-experiment=macros examples/algebraic_types.dart

Example

void main() {
  var w = W.Variant1(C(2));
  w = W.fromJson(w.toJson());
  assert(w is W$Variant1);
  print(w.toJson());
  w = W.Variant2(C(1), B("hello"));
  w = W.fromJson(w.toJson());
  assert(w is W$Variant2);
  print(w.toJson());
  switch (w) {
    case W$Variant1():
      print("Variant2");
    case W$Variant2():
      print("Variant2");
  }
}

@JsonCodable()
class C {
  int x;

  C(this.x);
}

@JsonCodable()
class B {
  String x;

  B(this.x);
}

@Enum(
    "Variant1(C)",
    "Variant2(C,B)"
)
class _W {}
1
likes
0
points
14
downloads

Publisher

unverified uploader

Weekly Downloads

Dart macros for algebraic types

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

json, macros

More

Packages that depend on algebraic_types