stifle v0.1.0 Stifle
Stifle is a library for suppressing side-effects (raises, exits, etc) in Elixir functions, allowing the developer to replay side effects in the current process or inspect the effect/return value safely.
Example
iex> raise_hell_fn = fn -> raise "hell" end
iex> stifled_fn = Stifle.stifle(raise_hell_fn)
iex> stifled_return_value = stifled_fn.() # => {:error, %RuntimeError{message: "hell"}, [...]}
iex> Stifle.unstifle(stifled_return_value)
** (RuntimeError) hell
Installation
Add Stifle to mix.exs
:
def deps do
[{:stifle, "~> 0.1.0"}]
end
def application do
[applications: [:stifle]]
end
Summary
Functions
Given a function that may have side-effects (exits, raises, throws), returns a side-effect-free function that returns a value representing the return value or side effect
Given the return value of a function emitted from stifle/1
, either return the return value or recreate the stifled side effects (exits, raises, throws) in the current process
Types
stifled_return_value ::
{:ok, any} |
{:exit, any} |
{:throw, any} |
{:error, Exception.t, [:erlang.stack_item]}
Functions
Specs
stifle((... -> any | no_return)) :: (... -> stifled_return_value)
Given a function that may have side-effects (exits, raises, throws), returns a side-effect-free function that returns a value representing the return value or side effect.
Specs
unstifle(stifled_return_value) :: any | no_return
Given the return value of a function emitted from stifle/1
, either return the return value or recreate the stifled side effects (exits, raises, throws) in the current process.