Skip to content

More raising helpers

Latest
Compare
Choose a tag to compare
@expede expede released this 28 Dec 12:27
· 10 commits to master since this release

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