Skip to content

Commit

Permalink
👕 fix credo issues
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdd authored Feb 15, 2024
1 parent a495424 commit 2349b76
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
20 changes: 10 additions & 10 deletions lib/rustic_result.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,24 @@ defmodule Rustic.Result do
def err(reason), do: {:error, reason}

@doc "Returns true if the Result is an Ok value"
@spec is_ok?(t()) :: boolean()
def is_ok?(:ok), do: true
def is_ok?({:ok, _}), do: true
def is_ok?({:error, _}), do: false
@spec ok?(t()) :: boolean()
def ok?(:ok), do: true
def ok?({:ok, _}), do: true
def ok?({:error, _}), do: false

@doc "Returns true if the Result is an Err value"
@spec is_err?(t()) :: boolean()
def is_err?(:ok), do: false
def is_err?({:ok, _}), do: false
def is_err?({:error, _}), do: true
@spec err?(t()) :: boolean()
def err?(:ok), do: false
def err?({:ok, _}), do: false
def err?({:error, _}), do: true

@doc "Is valid if and only if an Ok result is supplied"
defguard is_ok_result(val) when
defguard is_ok(val) when
val == :ok
or (is_tuple(val) and elem(val, 0) == :ok)

@doc "Is valid if and only if an Err result is supplied"
defguard is_err_result(val) when
defguard is_err(val) when
is_tuple(val) and elem(val, 0) == :error

@doc "Unwrap an Ok result, or raise an exception"
Expand Down
24 changes: 12 additions & 12 deletions test/rustic_result_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ defmodule Rustic.Result.Test do

import Rustic.Result

test "is_ok_result/1" do
test "is_ok/1" do
check = fn
val when is_ok_result(val) -> true
val when is_ok(val) -> true
_ -> false
end

Expand All @@ -15,9 +15,9 @@ defmodule Rustic.Result.Test do
assert not check.({:error, :failed})
end

test "is_err_result/1" do
test "is_err/1" do
check = fn
val when is_err_result(val) -> true
val when is_err(val) -> true
_ -> false
end

Expand All @@ -26,16 +26,16 @@ defmodule Rustic.Result.Test do
assert check.({:error, :failed})
end

test "is_ok?/1" do
assert :ok |> is_ok?()
assert ok(1) |> is_ok?()
assert not (err(:failed) |> is_ok?())
test "ok?/1" do
assert :ok |> ok?()
assert ok(1) |> ok?()
assert not (err(:failed) |> ok?())
end

test "is_err?/1" do
assert not (:ok |> is_err?())
assert not (ok(1) |> is_err?())
assert err(:failed) |> is_err?()
test "err?/1" do
assert not (:ok |> err?())
assert not (ok(1) |> err?())
assert err(:failed) |> err?()
end

test "unwrap!/1" do
Expand Down

0 comments on commit 2349b76

Please sign in to comment.