title: Scala's syntax of of work with anonymous objects in map() & flatMap()
body: <p>As example, I have the following Scala class(and the same in C#, ofc):</p>
  
  <pre><code>import com.github.nscala_time.time.Imports._
  
  class Flight{
    var FlDate:DateTime = new DateTime
    var Origin = ""
    var Destination = ""
  }
  </code></pre>
  
  <p>flights = Flight[]</p>
  
  <p>Original C# Code:</p>
  
  <pre><code>var rez = flights.SelectMany(p =&gt; new[] {
       new { Airport = p.Origin, IsOrigin = true },
       new { Airport = p.Destination, IsOrigin = false }
     })
     .GroupBy(x =&gt; x.Airport)
     .Select(g =&gt; new
     {
         Airport = g.Key,
         LeftCount = g.Count(x =&gt; x.IsOrigin),
         ArrivedCount = g.Count(x =&gt; !x.IsOrigin)
     });
  </code></pre>
  
  <p>Incorrect Scala code:</p>
  
  <pre><code>var rez = flights
    .flatMap(case (airport, isOrigin) =&gt; {
    new { airport = _.origin, isOrigin = true }, // issue - ?
    new { airport = _.destination, isOrigin = false } // issue - ?
  })
  .groupBy(_.airport)
  .map {
    case (airport, leftCount, arrivedCount) =&gt; new {
      val airport = ??? // issue - g.Key?
      val leftCount = ??? // issue - g.Count(x =&gt; x.IsOrigin) ?
      val arrivedCount = ??? // issue - g.Count(x =&gt; !x.IsOrigin) ?
    }
  }
  </code></pre>
  
  <p>So, as you see by the code, as result i need to have an array of objects with the following properties:  <code>ListBuffer[airport:String, leftCount :Int, arrivedCount:Int]</code> </p>
  
  <p>So...</p>
  
  <ol>
  <li>Can someone help to fix the code?</li>
  <li>Maybe, someone knows some good article about "syntax of work with anonymous objects in Scala" topic?</li>
  </ol>