Skip to content

feat(options): add second unsafeGet that operates on var Option[T] #25026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from

Conversation

Retrocast
Copy link

There is proc get*[T](self: var Option[T]): var T, seems reasonable to also have unsafe version of it, because it is impossible to get var T from var Option[T] without raising exceptions in a "safe" (or, rather, stdlib-provided) way. Since original unsafeGet didn't have runnableExamples, mine doesn't either, but simplest test case is the same as for the aforementioned get:

var
  x = some(42)
inc(x.unsafeGet)
assert x.unsafeGet == 43

^ it works fine with my PR, but doesn't compile without it:

Error: type mismatch
Expression: inc(unsafeGet(x))
  [1] unsafeGet(x): int

Expected one of (first mismatch at [position]):
[1] proc inc[T, V: Ordinal](x: var T; y: V = 1)
  expression 'unsafeGet(x)' is immutable, not 'var'

P.S. the #get,Option[T]_2 in doc comment just links to the version of get that accepts var Option[T] instead of normal one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant