title: In Elixir how do you sort a keyword list by value?
body: <p>I am trying to develop a simple POC in Elixir that requires information storage in a map. The problem is I cannot figure out how to display the map as list sorted by value.</p>
  
  <pre><code>defmodule MapUpdater do
      def update_score(map, player, :double), do: Map.update(map, player, 2, &amp;(&amp;1 * 2))
      def update_score(map, player, :halve), do: Map.update(map, player, .5, &amp;(&amp;1 * 0.5))
      def update_score(map, player, :penalize), do: Map.update(map, player, -1, &amp;(&amp;1 - 1))
      def view_scores(map, :top), do: Map.to_list(map) |&gt; Enum.sort_by(???)
      def view_scores(map, :bottom), do: Map.to_list(map) |&gt; Enum.sort_by(???)
  end
  </code></pre>
  
  <p>I have tried:</p>
  
  <pre><code>Enum.sort_by(&amp;(elem(&amp;1, 1)) &gt; &amp;(elem(&amp;2, 1)))
  </code></pre>
  
  <p>and any number of variations of this, but reading the Documentation over and over is not helping me. Any advice?</p>