Added ensure!/1
and def!/2
ensure
is essentially an alias for foo >>> fn x -> x end.()
ensure!([1, 2, 3])
#=> [1, 2, 3]
%ArgumentError{message: "raise me"} |> ensure!
#=> ** (ArgumentError) raise me
def! foo(...)
helps define a def foo(...)
plus def foo!(...)
variant that raises any final exception from foo
defmodule Foo do
use Exceptional
def! foo(a), do: a
end
Foo.foo([1, 2, 3])
#=> [1, 2, 3]
Foo.foo(%ArgumentError{message: "raise me"})
#=> %ArgumentError{message: "raise me"}
Foo.foo!([1, 2, 3])
#=> [1, 2, 3]
Foo.foo!(%ArgumentError{message: "raise me"})
#=> ** (ArgumentError) raise me