title: Why are the result keys of group-by function in order in most cases but not when using with range?
body: <p>I am working on <a href="http://www.4clojure.com/problem/56" rel="nofollow noreferrer">this problem</a></p>
  
  <p>My solution is:</p>
  
  <pre><code>(fn [s]
    (map #(first %) (group-by identity s)))
  </code></pre>
  
  <p>First three tests passed and the last one failed.</p>
  
  <p>Because</p>
  
  <pre><code>(group-by identity (range 50)
  </code></pre>
  
  <p>gives results unordered. But my solution strongly relies on the ordered feature of group-by function. That is to say the order of every key in the result map must be maintained. And this is almost true even though <a href="http://clojuredocs.org/clojure_core/clojure.core/group-by" rel="nofollow noreferrer">the Doc</a> doesn't guarantee that.</p>
  
  <p>The really weird thing is:</p>
  
  <p><img src="https://i.stack.imgur.com/kLWGE.png" alt="enter image description here"></p>
  
  <p>You see, when parameters are more than 32 group-by function gives wrong order. Results are not randomly but that the overflowed elements prepend after the first one.</p>
  
  <p>Why?</p>
  
  <p>How can I keep the ordered feature of group-by function or is there a better solution?</p>