Adds get for Option[T]. (#8462)
This commit is contained in:
parent
aa1cdebdc2
commit
feda366d86
1 changed files with 8 additions and 1 deletions
|
|
@ -129,7 +129,7 @@ proc get*[T](self: Option[T]): T =
|
||||||
## Returns contents of the Option. If it is none, then an exception is
|
## Returns contents of the Option. If it is none, then an exception is
|
||||||
## thrown.
|
## thrown.
|
||||||
if self.isNone:
|
if self.isNone:
|
||||||
raise UnpackError(msg : "Can't obtain a value from a `none`")
|
raise UnpackError(msg: "Can't obtain a value from a `none`")
|
||||||
self.val
|
self.val
|
||||||
|
|
||||||
proc get*[T](self: Option[T], otherwise: T): T =
|
proc get*[T](self: Option[T], otherwise: T): T =
|
||||||
|
|
@ -139,6 +139,13 @@ proc get*[T](self: Option[T], otherwise: T): T =
|
||||||
else:
|
else:
|
||||||
otherwise
|
otherwise
|
||||||
|
|
||||||
|
proc get*[T](self: var Option[T]): var T =
|
||||||
|
## Returns contents of the Option. If it is none, then an exception is
|
||||||
|
## thrown.
|
||||||
|
if self.isNone:
|
||||||
|
raise UnpackError(msg: "Can't obtain a value from a `none`")
|
||||||
|
return self.val
|
||||||
|
|
||||||
proc map*[T](self: Option[T], callback: proc (input: T)) =
|
proc map*[T](self: Option[T], callback: proc (input: T)) =
|
||||||
## Applies a callback to the value in this Option
|
## Applies a callback to the value in this Option
|
||||||
if self.isSome:
|
if self.isSome:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue