Skip to content

Commit

Permalink
_
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Jun 30, 2021
1 parent a63630d commit 797bee6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/pure/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ type
UnpackDefect* = object of Defect
UnpackError* {.deprecated: "See corresponding Defect".} = UnpackDefect

type MaybeOption[T](_: typedesc[T]) =
template maybeOption*[T](_: typedesc[T]): untyped =
## Return `T` if T is `ref | ptr | pointer | proc`, else `Option[T]`
runnableExamples:
assert maybeOption(ref int) is ref int
assert maybeOption(int) is Option[int]
when T is SomePointer: T
else: Option[T]

Expand All @@ -104,7 +108,7 @@ proc option*[T](val: sink T): Option[T] {.inline.} =
a: int
b: string

assert option[Foo](nil).isNone
assert option[Foo](nil).isSome
assert option(42).isSome

result.val = val
Expand Down

0 comments on commit 797bee6

Please sign in to comment.