title: Scala trait that accepts N size tuple and returns M sized tuple
body: <p>I'm currently developing a spark application that involves a series of complex joins between tuples, building out an N sized tuple based on the target data set.</p>
  
  <p>I come from a Java world and have been resolving specific fields from each element of a tuple into a new object. I know there has to be a better way to do this functionally.</p>
  
  <p>Example.</p>
  
  <pre><code>val obj1Obj2:  ((Int, (Object1, Object2)) = object1.join(object2)
  val obj3Resolve = obj1Obj2
      .map(a =&gt; a match {case (k,v) =&gt; v}}
      .map(a =&gt; (a._2.key, new Object3(a._2.key, a._1.foo, a._2.bar))
  </code></pre>
  
  <p>What I would like to do is to have a generic trait that I extend for each particular target object, taking in an arbitrary tuple and returning an arbitrary tuple. I've found that the joins themselves are relatively straightforward, it's the intermediate object declarations that bloat the code, as well as the restructuring of the tuples to rekey them for a future join, and I feel this is too "java" like.</p>
  
  <p>Any advice is much appreciated; I'm developing with spark so some Scala solutions may not apply.</p>
  
  <p>Thanks!</p>