Skip to content
/ total Public

Basic exhaustiveness checking of unions in Elixir

License

Notifications You must be signed in to change notification settings

lpil/total

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Basic exhaustiveness checking of unions in Elixir

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages