diff options
| author | Ginger Bill <bill@gingerbill.org> | 2016-10-06 23:30:22 +0100 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2016-10-06 23:30:22 +0100 |
| commit | f40482aa29f687b4630744457844bad7f45ec614 (patch) | |
| tree | f9d4cdec95d29197ce5a657c370eb3461e2cbbf4 /code | |
| parent | 50301557b2425fc0b4dd213ad03fb635cbd6e454 (diff) | |
Maybe types; value, ok := maybe_value(x)
Diffstat (limited to 'code')
| -rw-r--r-- | code/demo.odin | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/code/demo.odin b/code/demo.odin index 0d0ed6735..9b9566faa 100644 --- a/code/demo.odin +++ b/code/demo.odin @@ -1,15 +1,15 @@ #import "fmt.odin" -A :: {2}f32{1, 2} -B :: {2}f32{3, 4} - main :: proc() { - Fruit :: union { - A: int - B: f32 - C: struct { - x: int + maybe_print :: proc(x: ?int) { + if v, ok := maybe_value(x); ok { + fmt.println(v) + } else { + fmt.println("nowt") } } + + maybe_print(123) // 123 + maybe_print(nil) // nowt } |