Hi, all! I'm trying to get the first item out of an OrderedTable that was 
indexed with strings. I'm not sure which is the best way to do it.

My program is reading a set of configuration files and loading the information 
into a type `Target`, which is then added to an ordered table using the name of 
the target as its index. If the user executes a command that takes a target, I 
want to get the target using the supplied name as the index (just normalized). 
So far, so good. However, if the user does not specify a target, I want to 
select the first one that was added to the table.

Here's my types: 
    
    
    type
      Config* = object
        # ...
        targets*: OrderedTable[string, Target]
      
      Target = object
        name*, file*, description*: string
        sources*: seq[string]
    
    
    Run

This is the only way I can think of to get the first index: 
    
    
    if opts.target.len == 0:
      for target in cfg.targets.keys:
        opts.target = target
        break
     
    
    Run

Is there a better way of getting the first index? Or maybe a better way to 
structure my data that avoids this?

Thanks!

Reply via email to