diff --git a/questionable/results.nim b/questionable/results.nim index bfeaaeb..4f8811f 100644 --- a/questionable/results.nim +++ b/questionable/results.nim @@ -15,6 +15,9 @@ template `?!`*(T: typed): type Result[T, ref CatchableError] = proc success*[T](value: T): ?!T = ok(?!T, value) +proc success*: ?!void = + ok(?!void) + proc failure*(T: type, error: ref CatchableError): ?!T = err(?!T, error) diff --git a/testmodules/result/test.nim b/testmodules/result/test.nim index f6ba756..46601d2 100644 --- a/testmodules/result/test.nim +++ b/testmodules/result/test.nim @@ -112,6 +112,9 @@ suite "result": check parseInt("42").catch == 42.success check parseInt("foo").catch.error of ValueError + test "success can be called without argument": + check (success() is ?!void) + test "failure can be called with string argument": let value = int.failure("some failure") check value.error of ResultFailure