From 43f09e8c861082dc2a6596e0fe49f34e18aedec6 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Sat, 13 Mar 2021 11:10:05 +0100 Subject: [PATCH] Rename toOption() -> option() To match the style of std/options, where option() is also used to convert a ref to an Option. --- Readme.md | 2 +- questionable/results.nim | 2 +- testmodules/result/test.nim | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Readme.md b/Readme.md index 7e8d8be..f4051e9 100644 --- a/Readme.md +++ b/Readme.md @@ -186,7 +186,7 @@ let y = parseInt("XX").catch # equals int.failure(..) Any Result can be converted to an Option: ```nim -let converted = works().toOption # equals @[1, 1, 2, 2, 2].some +let converted = works().option # equals @[1, 1, 2, 2, 2].some ``` Banning Errors diff --git a/questionable/results.nim b/questionable/results.nim index fff6cb2..afb2b4a 100644 --- a/questionable/results.nim +++ b/questionable/results.nim @@ -38,7 +38,7 @@ template `=?`*[T](name: untyped{nkIdent}, value: ?!T): bool = template name: T {.used.} = value.unsafeGet() value.isOk -proc toOption*[T,E](value: Result[T,E]): ?T = +proc option*[T,E](value: Result[T,E]): ?T = if value.isOk: value.unsafeGet.some else: diff --git a/testmodules/result/test.nim b/testmodules/result/test.nim index c9bbbc8..fc8fbcd 100644 --- a/testmodules/result/test.nim +++ b/testmodules/result/test.nim @@ -112,8 +112,8 @@ suite "result": check (40.success > 42 == false.success) test "Result can be converted to Option": - check 42.success.toOption == 42.some - check int.failure(error).toOption == int.none + check 42.success.option == 42.some + check int.failure(error).option == int.none test "examples from readme work": @@ -149,5 +149,5 @@ suite "result": # Conversion to Option - let converted = works().toOption + let converted = works().option check (converted == @[1, 1, 2, 2, 2].some)