implement proc `==` and `contains` for you specialized type
    
    
    import sequtils
    
    type
        DataBuffer* = tuple
          key             : string
          mytype          : string
          value           : string
    
    proc `==`(a, b: DataBuffer): bool =
      a.key == b.key
    
    
    proc contains[T: DataBuffer](d: T, dbuf: seq[T]): bool =
      for data in dbuf:
          if d == data:
              return true
      false
    
    # change proc to be different to work with generic add
    proc dataAdd[T: DataBuffer](data: var seq[T], newdata: T): bool 
{.discardable.} =
      if newdata in data:
          data[data.find(newdata)] = newdata
          false
      else:
          data.add newdata
          true
    
    var mydata = newSeq[DataBuffer]()
    
    mydata.dataAdd(("a","int","4"))
    mydata.dataAdd(("a","int","5"))
    
    echo mydata # if expect only the last add to be visible ([a, int, 5])
    

With boolean return, you can know whether it replaced old value or add new to 
collections. You can just change the dataAdd to return DataBuffer so it will 
return old value that's be replaced or return a newly added value.

Reply via email to