www.ziglang.org
www.ziglang.org copied to clipboard
Not mentioned in docs: `else => |x|` in switch
This feature seems to exist but it's not mentioned in the docs.
else
supports a capture group which probably just returns the value that was in the switch(...)
. parentheses.
const std = @import("std");
pub fn main() void {
var b: i32 = 5;
switch (b) {
else => |x| std.debug.warn("{}\n", .{x}), // prints 5
}
}
the capture is supported on all arms of a switch to get the value that was passed in