From 144c70580a7c0b5f8032878c55ca442085427582 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Thu, 15 Apr 2021 11:04:26 +0200 Subject: [PATCH] Calling `success` without arguments returns ?!void result --- questionable/results.nim | 3 +++ testmodules/result/test.nim | 3 +++ 2 files changed, 6 insertions(+) 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