return generate();
}
+ #doc """
+ Returns the value inside the optional, if there is one.
+ If not, an assertion is thrown and the context's assert
+ handler must take care of it.
+ """
+ unwrap :: (o: Optional) -> o.Value_Type {
+ if o.has_value do return o.value;
+ assert(false, "Unwrapping empty Optional.");
+ }
+
+ or_return :: macro (o: Optional($T)) -> T {
+ value := o;
+ if value.has_value do return value.value;
+
+ return #from_enclosing .{};
+ }
+
hash :: (o: Optional($T/core.hash.Hashable)) -> u32 {
if !o.has_value do return 0;
return core.hash.to_u32(o.value);