Skip to content

Commit c424156

Browse files
committed
One more sketch
1 parent e0a7c95 commit c424156

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
fun example1() -> int? {
2+
if(thing) return none;
3+
else return 5; // anything that is not itself the desired Option type is automatically promoted to some
4+
}
5+
6+
fun example2(hello: int?) -> int?? {
7+
if(thing) return none;
8+
else return hello; // return some hello;
9+
}
10+
11+
fun create_class() -> SomeClass? {
12+
return new SomeClass { } // return some new SomeClass { }
13+
}
14+
15+
fun takes_pointer(ptr: Object?) -> Object?? {
16+
using ptr = ptr {
17+
return ptr; // some some ptr
18+
}
19+
20+
return ptr; // some <anything>
21+
}
22+
23+
class Container {
24+
var ponies: Array[Pony?];
25+
26+
impl Iterable[Pony?] {
27+
fun iter() -> Iterator[Pony?] {
28+
var i = 0;
29+
30+
fun () -> Pony?? {
31+
var idx = i;
32+
i += 1;
33+
if idx < ponies.length {
34+
return ponies[idx]; // return some ponies[idx]
35+
}
36+
return none;
37+
}
38+
}
39+
}
40+
}
41+
42+
fun matches(ptr: Pony?) {
43+
match ptr {
44+
some pony => "yay",
45+
none => "neigh",
46+
}
47+
}

0 commit comments

Comments
 (0)