Total
Basic exhaustiveness checking of unions in Elixir
Install / Use
/learn @lpil/TotalREADME
Total
Simple exhaustiveness checking of tuple + atom based unions.
defmodule MyType do
require Total
# define a union
Total.defunion(method() :: :get | :post | {:other, term()})
end
defmodule 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
def deps do
[
{:total, "~> 0.1.0"}
]
end
Related Skills
node-connect
341.8kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
341.8kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.6kCommit, push, and open a PR
