diff options
author | Louis Pilfold <louis@lpil.uk> | 2022-02-22 17:47:02 +0000 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2022-02-22 17:47:02 +0000 |
commit | 7b67ae1502b10edbb1589b831db1d8d856dc9b88 (patch) | |
tree | 1307267f1d50457a3fbae6a66c9d8d17de76826f /src | |
parent | ddd0135d4bba20e29e1367c3bef8bb47a8dbb0a3 (diff) | |
download | gleam_stdlib-7b67ae1502b10edbb1589b831db1d8d856dc9b88.tar.gz gleam_stdlib-7b67ae1502b10edbb1589b831db1d8d856dc9b88.zip |
result.unwrap_both
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam/result.gleam | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/gleam/result.gleam b/src/gleam/result.gleam index 5d77408..9f419b5 100644 --- a/src/gleam/result.gleam +++ b/src/gleam/result.gleam @@ -202,6 +202,28 @@ pub fn unwrap_error(result: Result(a, e), or default: e) -> e { } } +/// Extracts the inner value from a result. Both the value and error must be of +/// the same type. +/// +/// ## Examples +/// +/// ```gleam +/// > unwrap_both(Error(1)) +/// 1 +/// ``` +/// +/// ```gleam +/// > unwrap_both(Ok(2)) +/// 2 +/// ``` +/// +pub fn unwrap_both(result: Result(a, a)) -> a { + case result { + Ok(a) -> a + Error(a) -> a + } +} + /// Transforms any error into `Error(Nil)`. /// /// ## Examples |