aboutsummaryrefslogtreecommitdiff
path: root/std/default/options.pk
diff options
context:
space:
mode:
Diffstat (limited to 'std/default/options.pk')
-rw-r--r--std/default/options.pk18
1 files changed, 9 insertions, 9 deletions
diff --git a/std/default/options.pk b/std/default/options.pk
index f1bcac4..3aaea49 100644
--- a/std/default/options.pk
+++ b/std/default/options.pk
@@ -1,4 +1,4 @@
-## std/options
+## std/options: Optional types.
## This module is imported by default.
import std/format
@@ -47,20 +47,20 @@ pub func flatten[T](self: Option[Option[T]]): Option[T] = # todo: better name?
None
## Returns the inner value or a default.
-pub func or[T](self: Option[T], default: T): T =
+pub func get_or[T](self: Option[T], default: T): T =
if self of Some(x): x
else: default
## Directly accesses the inner value. Throws an exception if None.
-pub yeet func get[T](self: Option[T]): T =
+pub yeet func `!`[T](self: Option[T]): T =
if self of Some(x): x
else: raise Exception # todo: syntax??
-# todo: direct access, alias to get
-macro `!`[T](self: Option[T]): T
-# todo: indirect access, ??? do we propagate? is this useful? probably not
-macro `?`[T](self: Option[T]): T
-# todo: field access? useful? assignment?
-macro `.?`[T](self: Option[T])
+## Indirect access. Propagates None.
+pub macro `?`[T](self: Option[T]) =
+ quote:
+ match self
+ of Some(x): x
+ of None: return None
## Overloads the == operation for use on Options.
pub func `==`[T](a, b: Option[T]): bool =