mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 05:50:30 +00:00
Add TableRef version of mgetOrPut.
This commit is contained in:
@@ -397,6 +397,11 @@ proc mget*[A, B](t: TableRef[A, B], key: A): var B =
|
||||
## If `key` is not in `t`, the ``EInvalidKey`` exception is raised.
|
||||
t[].mget(key)
|
||||
|
||||
proc mgetOrPut*[A, B](t: TableRef[A, B], key: A, value: B): var B =
|
||||
## retrieves value at ``t[key]`` or puts ``value`` if not present, either way
|
||||
## returning a value which can be modified.
|
||||
t[].mgetOrPut(key, value)
|
||||
|
||||
proc hasKey*[A, B](t: TableRef[A, B], key: A): bool =
|
||||
## returns true iff `key` is in the table `t`.
|
||||
result = t[].hasKey(key)
|
||||
|
||||
Reference in New Issue
Block a user