Merge branch 'result-type'
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 27 Feb 2023 00:17:29 +0000 (18:17 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 27 Feb 2023 00:17:29 +0000 (18:17 -0600)
1  2 
core/container/optional.onyx

index e486e911679c957f92847435eb6ee33feb7fcb03,86f54d103a0978790947ae5112c27550e2292518..92a18794ecaf51870b00394feb27715f57a2fbbd
@@@ -83,13 -83,16 +83,23 @@@ Optional :: struct (Value_Type: type_ex
          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);