2024-05-16 20:29:11 +00:00
|
|
|
import std/tables, stew/templateutils
|
2024-01-16 16:27:40 +00:00
|
|
|
|
|
|
|
template keepItIf*[A, B](tableParam: var Table[A, B], itPredicate: untyped) =
|
|
|
|
bind evalTemplateParamOnce
|
|
|
|
evalTemplateParamOnce(tableParam, t):
|
|
|
|
var itemsToDelete: seq[A]
|
2024-03-15 23:08:47 +00:00
|
|
|
var key {.inject.}: A
|
|
|
|
var val {.inject.}: B
|
2024-01-16 16:27:40 +00:00
|
|
|
|
|
|
|
for k, v in t.mpairs():
|
|
|
|
key = k
|
|
|
|
val = v
|
|
|
|
if not itPredicate:
|
|
|
|
itemsToDelete.add(key)
|
|
|
|
|
|
|
|
for item in itemsToDelete:
|
|
|
|
t.del(item)
|
|
|
|
|
|
|
|
template keepItIf*[A, B](tableParam: var TableRef[A, B], itPredicate: untyped) =
|
|
|
|
bind evalTemplateParamOnce
|
|
|
|
evalTemplateParamOnce(tableParam, t):
|
|
|
|
var itemsToDelete: seq[A]
|
2024-03-15 23:08:47 +00:00
|
|
|
let key {.inject.}: A
|
|
|
|
let val {.inject.}: B
|
2024-01-16 16:27:40 +00:00
|
|
|
|
|
|
|
for k, v in t[].mpairs():
|
|
|
|
key = k
|
|
|
|
val = v
|
|
|
|
if not itPredicate:
|
|
|
|
itemsToDelete.add(key)
|
|
|
|
|
|
|
|
for item in itemsToDelete:
|
|
|
|
t[].del(item)
|