Minor correction to @mratsim \- if you want to iterate and break after the 
first then you can use _any_ of the table types, not only `OrderedTable`. E.g. 
    
    
    import tables
    var a = {1: "one", 2: "two"}.toTable
    for key, val in a:
      echo key
      break
    
    
    Run

Of course, Nim `Table` somewhat unusually allows keys to be duplicated (as in 
an C++ STL `multimap` but with no ordering guarantees). So, you cannot be sure 
(without more work) which of the possibly several entries that first slot 
corresponds to.

You may know that the keys are unique by construction/etc., though, and want to 
pop them off in whatever "fast order" is convenient. Indeed, the `HashSet` in 
`sets` even provides a `pop` proc. E.g., 
    
    
    import sets
    var a = ["one", "two"].toHashSet
    let x = a.pop
    echo x
    echo a
    
    
    Run

Reply via email to