Demonstrating a binding err

This commit is contained in:
Tomasz Bekas 2023-12-15 10:02:07 +01:00
parent 0c3d1dd563
commit fa97db70dd
No known key found for this signature in database
GPG Key ID: 4854E04C98824959
3 changed files with 32 additions and 0 deletions

8
main.nim Normal file
View File

@ -0,0 +1,8 @@
# Run this file:
# nim c -r main.nim
#
import ./somefn
import ./otherfn
discard int.someFn()

10
otherfn.nim Normal file
View File

@ -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

14
somefn.nim Normal file
View File

@ -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("")