aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gleam/result.gleam22
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