aboutsummaryrefslogtreecommitdiff
path: root/src/value.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/value.zig')
-rw-r--r--src/value.zig9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/value.zig b/src/value.zig
index d576074ba3..e667c566b9 100644
--- a/src/value.zig
+++ b/src/value.zig
@@ -2506,6 +2506,15 @@ pub const Value = extern union {
};
}
+ /// Value of the optional, null if optional has no payload.
+ pub fn optionalValue(val: Value) ?Value {
+ if (val.isNull()) return null;
+
+ // Valid for optional representation to be the direct value
+ // and not use opt_payload.
+ return if (val.castTag(.opt_payload)) |p| p.data else val;
+ }
+
/// Valid for all types. Asserts the value is not undefined.
pub fn isFloat(self: Value) bool {
return switch (self.tag()) {