title: Convert list to a map with key being an index in Scala
body: <p>I have a list of strings</p>
  
  <pre><code>val list = List("a", "b", "c", "d", "e")
  </code></pre>
  
  <p>and I want to have a map with keys as indexes of items in list. So I did the following:</p>
  
  <pre><code>def mapByIndexes(list: List[String]): Map[Int, String] = (1 to list.size).zip(list).toMap
  </code></pre>
  
  <p>However, the resulting map does not preserve the index order and I'm getting this as a result:</p>
  
  <pre><code>Map(5 -&gt; "e", 1 -&gt; "a", 2 -&gt; "b", 3 -&gt; "c", 4 -&gt; "d") 
  </code></pre>
  
  <p>How can I modify the code above so I'm getting a map with the following, natural order?</p>
  
  <pre><code>Map(1 -&gt; "a", 2 -&gt; "b", 3 -&gt; "c", 4 -&gt; "d", 5 -&gt; "e") 
  </code></pre>
  
  <p>Note: I'm aware that I can just sort the resulting map, but can I avoid that step and create a map that already preserves the order?</p>
  
  <p>Edit: Solution with <code>ListMap</code> described at <a href="https://stackoverflow.com/questions/6199186/scala-linkedhashmap-tomap-preserves-order">Scala LinkedHashMap.toMap preserves order?</a> works, but I don't like additional parentheses and <code>_*</code> for so simple thing. Isn't there anything else so I can just have a chaining? If not, I will accept @pamu answer.</p>