Files
pplus-library/mojo/stress/optional-lookup.mojo
T
alexm 568474d52f
Test (in pplus-core) / in-core (push) Failing after 28m44s
Initial commit
2026-11-12 22:23:48 -05:00

23 lines
729 B
Mojo

# probe: a function returning Optional, tested and unwrapped
# status: the expected output is Programming+'s interpreter's prediction; corpus.py verify confirms or refutes it on godbolt
# expect-stdout: ada at 0
# expect-stdout: cy at 2
# expect-stdout: dee missing
# expect-stdout: 0 None
def index_of(xs: List[String], x: String) -> Optional[Int]:
for i in range(len(xs)):
if xs[i] == x:
return i
return None
def main():
var names: List[String] = ["ada", "bo", "cy"]
for q in ["ada", "cy", "dee"]:
var r = index_of(names, q)
if r:
print(q, "at", r.value())
else:
print(q, "missing")
print(index_of(names, "ada"), index_of(names, "zed"))