The ADT.ex library aims to emulate algebraic data types in Elixir, and provides some safety features by forcing you to cover all possibilities and preventing dead code.

Basic Operation

The above example defines an option between Foo and Bar, and generates the necessary structs for you. You can create a Foo or Bar as normal:

ADT.ex helps you make sure that all of your cases are covered when you use these generated structs. For example, you might select between the two options using the case macro:

But failing to provide all necessary case statements will fail at compile time:

Using ADT.ex forces you to cover all edge cases when using its case macro, and also prevents you from writing dead code. The paths in the case macro must match the possible variants.