Skip to content

Instantly share code, notes, and snippets.

@mikdusan
Created September 26, 2023 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikdusan/b61cab3a4e851be3260ec5bed2b8d822 to your computer and use it in GitHub Desktop.
Save mikdusan/b61cab3a4e851be3260ec5bed2b8d822 to your computer and use it in GitHub Desktop.
multi optional pattern
const std = @import("std");
pub fn main() void {
const oa: ?u32 = 0;
const ob: ?u32 = 1;
const oc: ?u32 = 2;
// pattern without "else" codepath
outer: {
const a = oa orelse break :outer;
const b = ob orelse break :outer;
const c = oc orelse break :outer;
std.log.debug("a={} b={} c={}", .{a,b,c});
}
// pattern with "else" codepath
outer: {
inner: {
const a = oa orelse break :inner;
const b = ob orelse break :inner;
const c = oc orelse break :inner;
std.log.debug("a={} b={} c={}", .{a,b,c});
break :outer;
}
// else codepath
std.log.debug("one or more null", .{});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment