mirror of
https://github.com/logos-storage/questionable.git
synced 2026-01-05 23:33:12 +00:00
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:
|
Any Result can be converted to an Option:
|
||||||
|
|
||||||
```nim
|
```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
|
Banning Errors
|
||||||
|
|||||||
@ -38,7 +38,7 @@ template `=?`*[T](name: untyped{nkIdent}, value: ?!T): bool =
|
|||||||
template name: T {.used.} = value.unsafeGet()
|
template name: T {.used.} = value.unsafeGet()
|
||||||
value.isOk
|
value.isOk
|
||||||
|
|
||||||
proc toOption*[T,E](value: Result[T,E]): ?T =
|
proc option*[T,E](value: Result[T,E]): ?T =
|
||||||
if value.isOk:
|
if value.isOk:
|
||||||
value.unsafeGet.some
|
value.unsafeGet.some
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -112,8 +112,8 @@ suite "result":
|
|||||||
check (40.success > 42 == false.success)
|
check (40.success > 42 == false.success)
|
||||||
|
|
||||||
test "Result can be converted to Option":
|
test "Result can be converted to Option":
|
||||||
check 42.success.toOption == 42.some
|
check 42.success.option == 42.some
|
||||||
check int.failure(error).toOption == int.none
|
check int.failure(error).option == int.none
|
||||||
|
|
||||||
test "examples from readme work":
|
test "examples from readme work":
|
||||||
|
|
||||||
@ -149,5 +149,5 @@ suite "result":
|
|||||||
|
|
||||||
# Conversion to Option
|
# Conversion to Option
|
||||||
|
|
||||||
let converted = works().toOption
|
let converted = works().option
|
||||||
check (converted == @[1, 1, 2, 2, 2].some)
|
check (converted == @[1, 1, 2, 2, 2].some)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user