https://github.com/lpil/total
Basic exhaustiveness checking of unions in Elixir
https://github.com/lpil/total
elixir-lang exhaustiveness-checking macros
Last synced: 6 months ago
JSON representation
Basic exhaustiveness checking of unions in Elixir
- Host: GitHub
- URL: https://github.com/lpil/total
- Owner: lpil
- License: apache-2.0
- Created: 2019-06-23T20:30:40.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-06-23T20:31:14.000Z (over 6 years ago)
- Last Synced: 2025-03-24T09:21:09.568Z (7 months ago)
- Topics: elixir-lang, exhaustiveness-checking, macros
- Language: Elixir
- Homepage:
- Size: 6.84 KB
- Stars: 16
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Total
Simple exhaustiveness checking of tuple + atom based unions.
```elixir
defmodule MyType do
require Total# define a union
Total.defunion(method() :: :get | :post | {:other, term()})
enddefmodule Elsewhere do
require MyType# This is OK, all variants are covered
def method_string(m) do
MyType.method_case m do
:get -> "GET"
:post -> "POST"
{:other, t} -> t
end
end# This is a compile time error: missing `{:other, term()}`
def method_string(m) do
MyType.method_case m do
:get -> "GET"
:post -> "POST"
end
end
end
```The exhaustiness checking is very basic: bare atoms are checked and tuples
have their tag and length checked, but their arguments are unchecked.All other terms and guard clauses are ignored.
## Installation
```elixir
def deps do
[
{:total, "~> 0.1.0"}
]
end
```