Result[T] is ok(value) or error(...), which holds an Error.

ok #

ok(value: T) -> Result[T]
ok() -> Result[Void]
def main() -> Void
  puts(ok(3))
  puts(ok("yes"))
end
Output
ok(3)
ok("yes")

error #

error(message: String) -> Result[T]
error(message: String, kind: String, code: Int, details: Map[String, String], cause: Error) -> Result[T]
error(error: Error) -> Result[T]

With a String, it builds a new Error with that message, made at this call. The other fields come as named arguments, each optional and in any order; code and cause are stored as some(...) (Error). With an Error, it holds that same Error, so a case arm can pass an error on as a Result of another type. The type comes from an annotation, a return type, a parameter or a field.

def fail_now() -> Result[Int] = error("broken")

def main() -> Void
  puts(fail_now())
end
Output
error("broken")

Result.ok? #

Result.ok?(result: Result[T]) -> Bool
def main() -> Void
  puts("1".to_i.ok?)
  puts("one".to_i.ok?)
end
Output
true
false

Result.unwrap! #

Result.unwrap!(result: Result[T]) -> T

Gives the value, or stops the program with RUNTIME-UNWRAP-ERROR.

def main() -> Void
  puts("5".to_i.unwrap! * 2)
end
Output
10

Result.unwrap_or #

Result.unwrap_or(result: Result[T], default: T) -> T

Gives the value, or the default for an error. The default is always computed.

def main() -> Void
  puts("5".to_i.unwrap_or(0))
  puts("five".to_i.unwrap_or(0))
end
Output
5
0

Result.message #

Result.message(result: Result[T]) -> String

Gives the message of the error, or "" for a success.

def main() -> Void
  puts("five".to_i.message)
  puts("[" + "5".to_i.message + "]")
end
Output
cannot convert "five" to Int
[]