Maybe types; value, ok := maybe_value(x)
This commit is contained in:
1 parent
50301557b2
commit
f40482aa29
12 files changed
+309
-118
No files matched your search
+8
-8
@@ -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
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user