Tagged Unions

Tagged Unions#

case() Any#

A case in a tagged union.

tag() Any#

The tag of a tagged union.

tagged_union(*, frozen: bool = False, repr: bool = True, eq: bool = True, order: bool = False) Callable[[type[_T]], type[_T]]#
tagged_union(_cls: type[_T], *, frozen: bool = False, repr: bool = True, eq: bool = True, order: bool = False) type[_T]

Tagged union decorator.

A decorator that turns a dataclass into a tagged union.

Parameters:
  • frozen – Whether the tagged union should be frozen. If True, the __setattr__ and __delattr__ methods will be generated.

  • repr – If True, the __repr__ method will be generated.

  • order – If True, the __lt__ method will be generated. The first case will be considered the smallest with index 0 and the items will be compared as the tuple (index, value)

  • eq – If True, the __eq__ method will be generated.