Skip to content

Commit

Permalink
add unwrap to result (#78)
Browse files Browse the repository at this point in the history
feat: add unwrap to onepiece result
  • Loading branch information
yordis committed Apr 26, 2023
1 parent d4dd447 commit 81cdffc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions apps/one_piece_result/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

## v0.4.0 - 2023-04-26

- Added `OnePiece.Result.unwrap/1`.

## v0.3.1 - 2022-09-25

- Fix typespec of `OnePiece.Result.when_err/2`.
Expand Down
17 changes: 17 additions & 0 deletions apps/one_piece_result/lib/one_piece/result.ex
Original file line number Diff line number Diff line change
Expand Up @@ -667,4 +667,21 @@ defmodule OnePiece.Result do
err in OkUnwrapError ->
err(err.reason)
end

@doc """
Returns the contained `t:ok/0` value or `t:error/0` value from a `t:t/0`.
iex> 42
...> |> OnePiece.Result.ok()
...> |> OnePiece.Result.unwrap()
42
iex> "oops"
...> |> OnePiece.Result.err()
...> |> OnePiece.Result.unwrap()
"oops"
"""
@spec unwrap(result :: t) :: any
def unwrap({:ok, v}), do: v
def unwrap({:error, v}), do: v
end
2 changes: 1 addition & 1 deletion apps/one_piece_result/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule OnePiece.Result.MixProject do
use Mix.Project

@app :one_piece_result
@version "0.3.2"
@version "0.4.0"
@elixir_version "~> 1.13"
@source_url "https://github.com/straw-hat-team/beam-monorepo"

Expand Down

0 comments on commit 81cdffc

Please sign in to comment.