A Groovy Discriminated Union

Here’s a link to a Groovy discriminated union implementation.

About Discriminated Unions

Discriminated unions provide support for values that can be one of a number of named cases, possibly each with different values and types. Discriminated unions are useful for heterogeneous data:
  • Data that can have special cases, including valid and error cases
  • Data that varies in type from one instance to another
  • As an alternative for small object hierarchies.