> Note that, if the same key appears more than once, this will replace all 
> occurrences.
> 
> `... result.add ....`

`add` for tables is (finally) deprecated and IMO shouldn't be even mentioned to 
beginners. You should use `[]=` instead so you don't introduce duplicate keys 
unintentionally. (Note that `toOrdererdTable` uses `[]=` internally, so no 
duplicate keys there)
    
    
    proc replaceKey[K, V](tab: OrderedTable[K, V], old, new: K): 
OrderedTable[K, V] =
      for k, v in tab.pairs:
        if k == old:
          result[new] = v
        else:
          result[k] = v
    
    
    Run

Reply via email to