From f66c5e7f18256514d31038785054a9a129a47e23 Mon Sep 17 00:00:00 2001 From: luxick Date: Thu, 2 Jul 2020 20:10:37 +0200 Subject: [PATCH] Update README --- README.md | 23 +++++++++++++++++++++++ README.rst | 23 ----------------------- 2 files changed, 23 insertions(+), 23 deletions(-) create mode 100644 README.md delete mode 100644 README.rst diff --git a/README.md b/README.md new file mode 100644 index 0000000..1af49d0 --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# 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](https://nim-lang.org/docs/options.html) in that additional messages can be passed along with the presence or absence of a value. + +## Basic Usage +``` nim +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!" +``` \ No newline at end of file diff --git a/README.rst b/README.rst deleted file mode 100644 index 7aed502..0000000 --- a/README.rst +++ /dev/null @@ -1,23 +0,0 @@ -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 module improves upon the `options module`_ -in that additional messages can be passed along with the presence or absence of a value. - -Basic Usage ------------ -.. code-block:: nim - 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!" \ No newline at end of file