title: Converting List to Map using keys in Scala
body: <p>I am struggling with finding an elegant FP approach to solving the following problem in Scala:</p>
  
  <p>Say I have a set of candidate keys</p>
  
  <pre><code>val validKeys = Set("key1", "key2", "key3")
  </code></pre>
  
  <p>And a list that</p>
  
  <ol>
  <li>Starts with a key</li>
  <li>has some number of non-keys (> 0) between each key</li>
  <li>Does not end with a key</li>
  </ol>
  
  <p>For example:</p>
  
  <pre><code>val myList = List("key3", "foo", "bar", "key1", "baz")
  </code></pre>
  
  <p>I'd like to transform this list into a map by choosing using valid keys as the key and aggregating non-keys as the value.  So, in the example above:</p>
  
  <pre><code>("key3" -&gt; "foo\nbar", "key1" -&gt; "baz")
  </code></pre>
  
  <p>Thanks in advance.</p>