File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments