title: Is there a way to refactoring this match case function?
body: <p>I have this code that will repeat multiple times (more than 15 times) across my app. </p>
  
  <pre><code>val entityList = params.map(paramPair =&gt; {
  //THIS LINE DEPENDS ON THE ENTITY
  val entityX = new Entity1
  paramPair.foreach { case (key, value) =&gt; (key, value) match {
    //THIS BLOCK CHANGES DEPENDING THE ENTITY
    case (KEY1, v: TYPE1) =&gt; entityX setX v
    case (KEY2, v: TYPE2) =&gt; entityX setY v
    ...
    //END BLOCK
    case _ =&gt;
    }
  }
  entityX
  })
  </code></pre>
  
  <p>The only code that changes are the type of entity and the pattern matching case clauses. Is there a way to create a function that receive those cases to avoid code repetition?</p>