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.pk26
1 files changed, 13 insertions, 13 deletions
diff --git a/std/default/options.pk b/std/default/options.pk
index 3aaea49..bbe0d9c 100644
--- a/std/default/options.pk
+++ b/std/default/options.pk
@@ -12,30 +12,30 @@ pub func is_some[T](self: Option[T]): bool =
pub func is_none[T](self: Option[T]): bool =
not self.is_some
-## Converts an Option[T] to a Result[T, E] given a user-provided error.
+## Converts an `Option[T]` to a `Result[T, E]` given a user-provided error.
pub func err[T, E](self: Option[T], error: E): Result[T, E] =
if self of Some(x):
Okay(x)
else:
Error(error)
-## Applies a function to T, if it exists.
-pub func map[T, U](self: Option[T], proc: T -> U): Option[U] =
+## Applies a function to `T`, if it exists.
+pub func map[T, U](self: Option[T], fn: T -> U): Option[U] =
if self of Some(x):
- Some(x.proc)
+ Some(fn(x))
else:
None
-## Converts T to a None, if proc returns false and it exists.
-pub func filter[T](self: Option[T], proc: T -> bool): Option[T] =
- if self of Some(x) and proc(x):
+## Converts `T` to a `None`, if `fn` returns false and it exists.
+pub func filter[T](self: Option[T], fn: T -> bool): Option[T] =
+ if self of Some(x) and fn(x):
Some(x)
else:
None
-## Applies a function to T, if it exists. Equivalent to .map(func).flatten.
-pub func flatmap[T, U](self: Option[T], proc: T -> Option[U]): Option[U] =
+## Applies a function to T, if it exists. Equivalent to `self.map(fn).flatten`.
+pub func flatmap[T, U](self: Option[T], fn: T -> Option[U]): Option[U] =
if self of Some(x):
- x.proc
+ fn(x)
else:
None
## Converts from Option[Option[T]] to Option[T].
@@ -55,14 +55,14 @@ pub yeet func `!`[T](self: Option[T]): T =
if self of Some(x): x
else: raise Exception # todo: syntax??
-## Indirect access. Propagates None.
+## 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.
+## Overloads the `==` operation for use on Options.
pub func `==`[T](a, b: Option[T]): bool =
match (a, b)
of (Some(x), Some(y)):
@@ -70,7 +70,7 @@ pub func `==`[T](a, b: Option[T]): bool =
of _:
false
-## Overloads the str() function for use on Options.
+## Overloads the `str()` function for use on Options.
pub func str[T](self: Option[T]): str =
if self of Some(x):
fmt("some({})", x.str)