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:
parent
b8e52b6acf
commit
43f09e8c86
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue