Rename toOption() -> option()

To match the style of std/options, where option() is also used
to convert a ref to an Option.
This commit is contained in:
Mark Spanbroek 2021-03-13 11:10:05 +01:00
parent b8e52b6acf
commit 43f09e8c86
3 changed files with 5 additions and 5 deletions

View File

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

View File

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

View File

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