ExUnion - Tagged Unions for Elixir. Just that.
ExUnion
is meant to be a lightweight, elixir-y implementation of tagged unions (also called variant, discriminated union, sum type, etc.).
While conventionally Elixir tends to promote using tuples to model tagged unions - the {:ok, …} | {:error, …}
pattern being a good example of that - this approach arguably lacks expressiveness, especially when modeling non-trivial unions. An alternative is to employ structs to model the individual cases of a tagged union, which works nicely but has the disadvantage of requiring significant boilerplate code.
ExUnion
attempts to bridge this gap by generating the necessary boilerplate (and a bit more) through a concise albeit opinionated DSL.
Read next Search millions of usernames efficiently with Ecto