2020-07-07 15:53:00 +02:00
2020-07-07 15:53:00 +02:00
2020-07-07 15:53:00 +02:00
2020-07-07 15:53:00 +02:00
2020-07-02 20:05:04 +02:00
2020-07-07 15:53:00 +02:00
2020-07-02 20:10:37 +02:00

op

Generic, exception-free return values.

OP stands for "Operation Result".

This module contains a generic type that can be used as a return type for operations that could fail. It adds additional messages to the result. This improves upon the options module in that additional messages can be passed along with the presence or absence of a value.

Basic Usage

import op

proc divide(a, b: int): OP[float] =
  ## This could fail
  if b == 0:
    return fail "Cannot divide by zero!"
  else:
    return ok a / b   # Wrap the result

let r = divide(42, 0)
assert r.isOk == false
assert r.error == "Cannot divide by zero!"
Description
Generic result types.
Readme 62 KiB
Languages
Nim 100%