aboutsummaryrefslogtreecommitdiff
path: root/std/default/results.pk
diff options
context:
space:
mode:
Diffstat (limited to 'std/default/results.pk')
-rw-r--r--std/default/results.pk16
1 files changed, 13 insertions, 3 deletions
diff --git a/std/default/results.pk b/std/default/results.pk
index 4e4d27a..8faf0c0 100644
--- a/std/default/results.pk
+++ b/std/default/results.pk
@@ -3,20 +3,30 @@
import std/[options, format]
+## The Result type.
+## A type that represents either success or failure.
pub type Result[T, E] = union
Okay: T
Error: E
-pub type Error = interface
+## The Err interface. Useful for dynamically dispatching errors.
+pub type Err = interface
str(Self): str
dbg(Self): str
-pub type Result[T] = Result[T, ref Error]
+## A `Result` type that uses dynamically dispatched errors.
+## The `Error` may be any type implementing `Err`.
+pub type Result[T] = Result[T, ref Err]
+## A `Result` type that only checks for success.
+## Does not contain a value.
+pub type Success[E] = Result[Unit, E]
+## Checks if a `Result` type was successful.
pub func is_ok[T, E](self: Result[T, E]): bool =
self of Okay(_)
+## Checks if a `Result` type was not successful.
pub func is_err[T, E](self: Result[T, E]): bool =
- not self.is_ok
+ self of Error(_)
## Converts from a `Result[T, E]` to an `Option[T]`.
pub func ok[T, E](self: Result[T, E]): Option[T] =