Add structured coroutines and explicit error handling
This commit is contained in:
parent
de1262b4cf
commit
fe62e81152
31 changed files with 1701 additions and 325 deletions
18
examples/results.gt
Normal file
18
examples/results.gt
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package main
|
||||
|
||||
import strconv
|
||||
import os
|
||||
|
||||
fun parse(value: String): Result<Int, Error> {
|
||||
return strconv.atoi(value)
|
||||
}
|
||||
|
||||
fun changeDirectory(path: String): Result<Unit, Error> {
|
||||
return os.chdir(path)
|
||||
}
|
||||
|
||||
fun main() {
|
||||
println(parse("42").unwrap())
|
||||
println(parse("invalid").unwrapOr(0))
|
||||
changeDirectory(".").unwrap()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue