From fa97db70dd5718b05448b927f5199f1f6b8445a3 Mon Sep 17 00:00:00 2001 From: Tomasz Bekas Date: Fri, 15 Dec 2023 10:02:07 +0100 Subject: [PATCH] Demonstrating a binding err --- main.nim | 8 ++++++++ otherfn.nim | 10 ++++++++++ somefn.nim | 14 ++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 main.nim create mode 100644 otherfn.nim create mode 100644 somefn.nim diff --git a/main.nim b/main.nim new file mode 100644 index 00000000..5016a731 --- /dev/null +++ b/main.nim @@ -0,0 +1,8 @@ +# Run this file: +# nim c -r main.nim +# + +import ./somefn +import ./otherfn + +discard int.someFn() diff --git a/otherfn.nim b/otherfn.nim new file mode 100644 index 00000000..d091e230 --- /dev/null +++ b/otherfn.nim @@ -0,0 +1,10 @@ + +import pkg/questionable +import pkg/questionable/results + +import ./somefn + +proc otherFn*(): void = + + without x =? int.someFn(), err: + echo "was err" & err.msg diff --git a/somefn.nim b/somefn.nim new file mode 100644 index 00000000..94c6ff69 --- /dev/null +++ b/somefn.nim @@ -0,0 +1,14 @@ +import pkg/questionable +import pkg/questionable/results + +proc someFn*( + X: type int +): ?!int = + let res = success(1) + + if err =? res.errorOption: + echo "err" & err.msg + else: + echo "no err" + + failure("")