For array/seq (which known as openArray when used as argument type), we can 
define the type easily by explicitly type the first element type like
    
    
    let int8Arr = [byte 1, 2, 3, 4, 5] // array[0..4, byte]
    var int16seq = @[1'i16, 2, 3, 4, 5] // seq[int16]
    
    
    Run

But not so with tuple
    
    
    let cstrarr = [(cstring"one", 1), ("two", 2), ("three", 3)] # will yield 
compile error
    
    
    Run

So we have no other choice other type manually to convert it, or resort to 
proc/template to convert it
    
    
    proc headers[V](hds: varargs[(string, V)]): (cstring, V) =
        result = @[]   # newer Nim doesn't have to initialize it anymore
        
        # notice the we add the "tuple", so add space after proc `add`
        # ofc we can also write it like result.add((cstring k, v))
        # when in doubt which to use, use parenthesis
        for k, v in hds: result.add (cstring k, v)
    
    
    Run

Reply via email to