diff options
author | Dominik Picheta <dominikpicheta@googlemail.com> | 2018-08-14 00:09:08 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-08-14 01:09:08 +0200 |
commit | feda366d86e723ff1877a1751cb3eadde8b00cb0 (patch) | |
tree | e7a80a67fb98e7a3c34d9e290cba1965fea46ddf /lib/pure/options.nim | |
parent | aa1cdebdc206857902081b4862dad2c2990179e8 (diff) | |
download | Nim-feda366d86e723ff1877a1751cb3eadde8b00cb0.tar.gz |
Adds get for Option[T]. (#8462)
Diffstat (limited to 'lib/pure/options.nim')
-rw-r--r-- | lib/pure/options.nim | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/pure/options.nim b/lib/pure/options.nim index ce58943f9..b547c722a 100644 --- a/lib/pure/options.nim +++ b/lib/pure/options.nim @@ -129,7 +129,7 @@ proc get*[T](self: Option[T]): 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`") + raise UnpackError(msg: "Can't obtain a value from a `none`") self.val proc get*[T](self: Option[T], otherwise: T): T = @@ -139,6 +139,13 @@ proc get*[T](self: Option[T], otherwise: T): T = else: 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)) = ## Applies a callback to the value in this Option if self.isSome: |