summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2022-08-25 15:21:46 +0800
committerGitHub <noreply@github.com>2022-08-25 03:21:46 -0400
commit16f6dc05fdb2e1ca3086936c15c2ad3de542d991 (patch)
tree9e844cf58f4639ae4d79c293b09680a94b54abbb
parent404e91ce48862c2a7f5e871cce41409d7301fa81 (diff)
downloadNim-16f6dc05fdb2e1ca3086936c15c2ad3de542d991.tar.gz
std/options enables stricteffects (#19441)
-rw-r--r--lib/pure/options.nim12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/pure/options.nim b/lib/pure/options.nim
index 562ed6361..9dc4e096b 100644
--- a/lib/pure/options.nim
+++ b/lib/pure/options.nim
@@ -68,6 +68,10 @@ supports pattern matching on `Option`s, with the `Some(<pattern>)` and
 ]##
 # xxx pending https://github.com/timotheecour/Nim/issues/376 use `runnableExamples` and `whichModule`
 
+when defined(nimHasEffectsOf):
+  {.experimental: "strictEffects".}
+else:
+  {.pragma: effectsOf.}
 
 import typetraits
 
@@ -226,7 +230,7 @@ proc get*[T](self: var Option[T]): var T {.inline.} =
     raise newException(UnpackDefect, "Can't obtain a value from a `none`")
   return self.val
 
-proc map*[T](self: Option[T], callback: proc (input: T)) {.inline.} =
+proc map*[T](self: Option[T], callback: proc (input: T)) {.inline, effectsOf: callback.} =
   ## Applies a `callback` function to the value of the `Option`, if it has one.
   ##
   ## **See also:**
@@ -245,7 +249,7 @@ proc map*[T](self: Option[T], callback: proc (input: T)) {.inline.} =
   if self.isSome:
     callback(self.val)
 
-proc map*[T, R](self: Option[T], callback: proc (input: T): R): Option[R] {.inline.} =
+proc map*[T, R](self: Option[T], callback: proc (input: T): R): Option[R] {.inline, effectsOf: callback.} =
   ## Applies a `callback` function to the value of the `Option` and returns an
   ## `Option` containing the new value.
   ##
@@ -282,7 +286,7 @@ proc flatten*[T](self: Option[Option[T]]): Option[T] {.inline.} =
     none(T)
 
 proc flatMap*[T, R](self: Option[T],
-                    callback: proc (input: T): Option[R]): Option[R] {.inline.} =
+                    callback: proc (input: T): Option[R]): Option[R] {.inline, effectsOf: callback.} =
   ## Applies a `callback` function to the value of the `Option` and returns the new value.
   ##
   ## If the `Option` has no value, `none(R)` will be returned.
@@ -307,7 +311,7 @@ proc flatMap*[T, R](self: Option[T],
 
   map(self, callback).flatten()
 
-proc filter*[T](self: Option[T], callback: proc (input: T): bool): Option[T] {.inline.} =
+proc filter*[T](self: Option[T], callback: proc (input: T): bool): Option[T] {.inline, effectsOf: callback.} =
   ## Applies a `callback` to the value of the `Option`.
   ##
   ## If the `callback` returns `true`, the option is returned as `some`.