title: Issue mapping a list of values into a class Scala
body: <p>I have two classes:</p>
  
  <pre><code>class Person(name: String)
  class Persons(people: List[Persons]
  </code></pre>
  
  <p>I want to create a companion object that accepts a list of Strings, makes each one into a person, and creates a Persons object. </p>
  
  <pre><code>object Persons {
      def apply(people: List[String]) = new Persons(people.map(_ =&gt; new Person(_)))
  }
  </code></pre>
  
  <p>However, this doesn't work. It turns out that</p>
  
  <pre><code>people.map(_ =&gt; new Person(_)) 
  </code></pre>
  
  <p>Is creating a function mapping </p>
  
  <pre><code>List[(String) =&gt; Person]
  </code></pre>
  
  <p>I managed to get the result I'm after using a for comprehension, but I'm unclear as to what's going on using map. </p>
  
  <pre><code>def apply(ppl: List[String]): Persons = {
      new Persons(for {
      p &lt;- ppl
      person = new Person(p)
  } yield person)
  </code></pre>
  
  <p>}</p>
  
  <p>Can anyone show me how to accomplish this using map and maybe explain what's going in my incorrect attempt?</p>