title: Storing iterator on a map in Scala
body: <p>I need to store an iterator on a Map to implement a traversal of a trie. In Java I did: </p>
  
  <pre><code>class Node {
  
    HashMap&lt;Character, Node&gt; children = new HashMap&lt;&gt;();
    Iterator&lt;Character&gt; i = children.keySet().iterator();
  
    public boolean hasNext() {
      return i.hasNext();
    }
  
    public CharNode next() {
      Character letter = i.next();
      return new CharNode(letter, children.get(letter));
    }
  ...
  </code></pre>
  
  <p>The reason I am doing this is that I use a queue to traverse the trie, and the iterators maintain the state of the traversal. </p>
  
  <p>In Scala, I couldn't figure out how to create the corresponding iterator though, unless I fall back on Java util.Iterator, and Java util.Map. Is there a more idiomatic way to do this in Scala?</p>