All Projects → lpil → total

lpil / total

Licence: Apache-2.0 License
Basic exhaustiveness checking of unions in Elixir

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to total

unreachable
Utility function for exhaustiveness checking with typed JS (TS or Flow)
Stars: ✭ 14 (-6.67%)
Mutual labels:  exhaustiveness-checking
ExhaustiveMatching
C# Analyzer Adding Exhaustive Checking of Switch Statements and Expressions
Stars: ✭ 60 (+300%)
Mutual labels:  exhaustiveness-checking

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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].