diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2021-02-24 14:17:16 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-24 22:17:16 +0000 |
commit | 578d1ee751fa8165a64c842c40216a752caf47e2 (patch) | |
tree | ef042ffd3c2797e7c51b9fc1eb68d209b05193fd /lib/pure/options.nim | |
parent | a4e6b242d56d80df004bf625643fcb3c9d3f1b7f (diff) | |
download | Nim-578d1ee751fa8165a64c842c40216a752caf47e2.tar.gz |
`std/options`: `$some(3)` is now `"some(3)"`, etc. (#17147)
* std/options: $some(3) is now "some(3)", not "Some(3)", `$none(int)` is now `"none(int)"` instead of `"None[int]"` * fix tests * disable optionsutils
Diffstat (limited to 'lib/pure/options.nim')
-rw-r--r-- | lib/pure/options.nim | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/lib/pure/options.nim b/lib/pure/options.nim index 69feee7dc..63e3598f0 100644 --- a/lib/pure/options.nim +++ b/lib/pure/options.nim @@ -306,8 +306,8 @@ proc flatMap*[T, R](self: Option[T], proc filter*[T](self: Option[T], callback: proc (input: T): bool): Option[T] {.inline.} = ## Applies a `callback` to the value of the `Option`. ## - ## If the `callback` returns `true`, the option is returned as `Some`. - ## If it returns `false`, it is returned as `None`. + ## If the `callback` returns `true`, the option is returned as `some`. + ## If it returns `false`, it is returned as `none`. ## ## **See also:** ## * `flatMap proc <#flatMap,Option[A],proc(A)>`_ @@ -325,8 +325,8 @@ proc filter*[T](self: Option[T], callback: proc (input: T): bool): Option[T] {.i self proc `==`*[T](a, b: Option[T]): bool {.inline.} = - ## Returns `true` if both `Option`s are `None`, - ## or if they are both `Some` and have equal values. + ## Returns `true` if both `Option`s are `none`, + ## or if they are both `some` and have equal values. runnableExamples: let a = some(42) @@ -346,18 +346,24 @@ proc `==`*[T](a, b: Option[T]): bool {.inline.} = proc `$`*[T](self: Option[T]): string = ## Get the string representation of the `Option`. runnableExamples: - assert $some(42) == "Some(42)" - assert $none(int) == "None[int]" + assert $some(42) == "some(42)" + assert $none(int) == "none(int)" if self.isSome: - result = "Some(" + when defined(nimLagacyOptionsDollar): + result = "Some(" + else: + result = "some(" result.addQuoted self.val result.add ")" else: - result = "None[" & name(T) & "]" + when defined(nimLagacyOptionsDollar): + result = "None[" & name(T) & "]" + else: + result = "none(" & name(T) & ")" proc unsafeGet*[T](self: Option[T]): lent T {.inline.}= - ## Returns the value of a `Some`. The behavior is undefined for `None`. + ## Returns the value of a `some`. The behavior is undefined for `none`. ## ## **Note:** Use this only when you are **absolutely sure** the value is present ## (e.g. after checking with `isSome <#isSome,Option[T]>`_). |