title: How to convert Map[A, B] into a key-value string sorted by String?
body: <p>Suppose I have a Map:</p>
  
  <pre><code>val m = Map("foo" -&gt; 10, "bar" -&gt; 5)
  </code></pre>
  
  <p>I want to convert this into a String in the following format (keys and values are separated by ":", different elements are separated by ","):</p>
  
  <pre><code>"bar:5,foo:10"
  </code></pre>
  
  <p>Note that the keys are now ordered.</p>
  
  <p>How do I write a function to perform this conversion generically? I tried</p>
  
  <pre><code>def f[A, B](m: Map[A, B]): String = {
    m.toList.sortBy(_._1).map { x =&gt; x._1 + ":" + x._2 }.mkString(",")
  }
  </code></pre>
  
  <p>But this doesn't work, because somehow I need to specify that <code>A</code> is orderable. I'm not sure how to do this -- I tried adding an implicit <code>Orderer</code> parameter to my function, but it didn't work.</p>