Skip to content
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

[TODO] add items(table) to allow using algorithms on a table #9217

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/pure/collections/tables.nim
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,16 @@ iterator mpairs*[A, B](t: var Table[A, B]): (A, var B) =
for h in 0..high(t.data):
if isFilled(t.data[h].hcode): yield (t.data[h].key, t.data[h].val)

iterator items*[A,B](t: Table[A,B]): tuple[key: A, val: B] =
## iterates over (key, value) tuples in the table `t`.
runnableExamples:
import sequtils
let a = {10: "foo", 12: "bar"}.toTable
doAssert mapIt(a, it.key) == [10, 12]
doAssert mapIt(a, it.val)[1] == "bar"
for key, val in t:
yield (key: key, val: val)

iterator keys*[A, B](t: Table[A, B]): A =
## iterates over any key in the table `t`.
for h in 0..high(t.data):
Expand Down