union 0.0.3 copy "union: ^0.0.3" to clipboard
union: ^0.0.3 copied to clipboard

discontinuedreplaced by: freezed
outdated

Type safe union types for dart, by using extensions from Dart 2.6

example/example.dart

import 'package:union/union.dart';

void main() {
  Union2<int, double> union2 = 42.asFirst();

  Union3<int, double, String> upcast = union2; // works
  print(upcast.value); // 42

  print(upcast.map((a) => a * 2, (a) => '$a', (a) => a).value); // 84

  upcast = 'foo'.asThird();

  print(upcast.map((a) => a * 2, (a) => '$a', (a) => a).value); // 'foo'

  // Union2<int, double> downcast = upcast; // does not compile
}
20
likes
40
pub points
47%
popularity

Publisher

verified publisherdash-overflow.net

Type safe union types for dart, by using extensions from Dart 2.6

Repository (GitHub)
View/report issues

License

MIT (license)

More

Packages that depend on union