fluttercommunity / dart_sealed_unions

Sealed Unions for Dart. Maintainer: @nodinosaur
https://pub.dev/packages/sealed_unions
Apache License 2.0
66 stars 7 forks source link

Default toString #16

Open antholeole opened 3 years ago

antholeole commented 3 years ago

Hi! I'm using this package and when writing tests, I often get failed messages like:

<instance of MySealedUnion> does not match <instance of MySealedUnion>

which makes it a little difficult to debug. My proposed solution is an override of the toString method for every union that looks like the following:

class Union4Impl<A, B, C, D> {
  @override
  String toString() => "$union4Impl:${join((a) => a.toString(), (b) => b.toString(), (c) => c.toString(), (d) => a.toString())}";

all the information still stays: this is a union 4 impl, but we pass down the toString to the actual class that is there.

let me know if we're open to a PR :)