module Std::Option { import Std::Io::{PrintLine}; extern func bux_exit(code: int); enum Option { Some(T), None, } func Option_NewSome(value: T) -> Option { let o: Option = Option { tag: Option_Some }; o.data.Some_0 = value; return o; } func Option_NewNone() -> Option { return Option { tag: Option_None }; } func Option_IsSome(o: Option) -> bool { return o.tag == Option_Some; } func Option_IsNone(o: Option) -> bool { return o.tag == Option_None; } func Option_Unwrap(o: Option) -> T { if o.tag != Option_Some { PrintLine("panic: unwrap on None"); bux_exit(1); } return o.data.Some_0; } func Option_UnwrapOr(o: Option, fallback: T) -> T { if o.tag == Option_Some { return o.data.Some_0; } return fallback; } func Option_Expect(o: Option, msg: String) -> T { if o.tag != Option_Some { PrintLine(msg); bux_exit(1); } return o.data.Some_0; } func Option_Or(o: Option, other: Option) -> Option { if o.tag == Option_Some { return o; } return other; } }