Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import options
- type
- Result*[T] = object
- Err: T
- Ok: T
- var
- res: Result[bool]
- proc is_ok[T](): T =
- if res.Ok:
- return true
- elif res.Err:
- return false
- proc is_err[T](): T =
- return not is_ok()
- proc ok*[T](x: T): Option[T] =
- case res
- of res.Ok: some(x)
- of res.Err: none()
- proc err*[T](x: T): Option[T] =
- case res
- of res.err(): some(x)
- of res.ok(x): none()
- proc add(x: int, y: int): Result[string] =
- if x == y:
- discard ok("fine")
- elif x != y:
- discard err("Not Working")
- echo(add(3,2))
Advertisement
Add Comment
Please, Sign In to add comment