refinery v0.1.0 Refinery
Refinery is an Elixir library for defining sets of refinement types (refered to as “algebras”) and converting Elixir terms to and from these types.
Examples
use Refinery
defalgebra MyAlgebra do
deftype MyAtom do
refine(&is_atom/1)
end
deftype MyString do
refine(&is_binary/1)
end
deftype MyInteger do
refine(&is_integer/1)
end
end
An algebra is a grouping of types. Algebras are useful for organizing types by their useage.
A Refinery Algebra is a moduel that implements the following functions:
__algebra__/0
: returns all types within the algebra.
You can define a new Refinery Algebra with the defalgebra/2
macro:
defalgebra Foo do
end
This will generate a new module called Foo
.
A Refinery Type is a module that implements the following functions:
__refine__/1
: accepts any Elixir term and returns{:ok, term}
or{:error, %RefinementError{}}
.
The Refinery DSL is a small set of functions that allow you to easily define types of a particular algebra.
deftype/2
: generates a new Refinery Type with an empty refinement pipeline.refine/1
: adds the given remote or local function reference to the Type’s refinement pipeline.