Last week I have been playing a lot with specs and types and as homework I created Tyyppi
library that allows dealing with types in runtime. It’s currently in a kindergarten, but it already might provide some goodness, including but not limited to:
- runtime check if this term is of that type with
Tyyppi.of?/2
, e. g.Tyyppi.of?(GenServer.on_start(), :ok)
(it’s apparently not)
- apply the function providing its spec so that it returns
{:ok, result}
if and only if all the arguments and the result meet the specs, and{:error, {:arity | :args | :result, value}}
otherwise - create a typed struct with generated complete detailed
t() :: %...{...}
type definition, type checks on upserts, and a possibility to cast values on upserts to the expected type (TBD).
I am aware of great TypeCheck
library by @Qqwy but my main goal was to stay as close to standard specs as possible. Tyyppi
does by no means compete with TypeCheck
.