title: Compose update query based on optional values
body: <p>The below function has a UUID param and then two optional parameters. Depending on the state of the two optional parameters will determine whether or not they are included in the update query.</p>
  <pre class="lang-scala prettyprint-override"><code>    def updateChunkState(chunkId: UUID, state: ChunkState, comment: Option[String], sourceLanguage: Option[String]): Either[ChunkNotFoundError, Unit] = {
        
        val result = (comment, sourceLanguage) match {
          case (c: Some[String], s: Some[String]) =&gt; {
            val query = ChunkTable.query.filter(_.id === chunkId.toString).map(c =&gt; (c.state, c.comment, c.sourceLanguage))
            exec(query.update(state, comment, sourceLanguage)) 
          }
          case (c: Some[String], None) =&gt; { 
            val query = ChunkTable.query.filter(_.id === chunkId.toString).map(c =&gt; (c.state, c.comment))
            exec(query.update(state, comment)) 
          }
          case (None, s: Some[String]) =&gt; {
            val query = ChunkTable.query.filter(_.id === chunkId.toString).map(c =&gt; (c.state, c.sourceLanguage))
            exec(query.update(state, sourceLanguage)) 
          }
          case (None, None) =&gt; {
            val query = ChunkTable.query.filter(_.id === chunkId.toString).map(c =&gt; (c.state))
            exec(query.update(state)) 
  
          }
        }
        result match {
          case 0 =&gt; Left(ChunkNotFoundError(chunkId))
          case n if n &gt; 0 =&gt; Right(())
        } 
  
      }
  
  </code></pre>
  <p>I believe there should be a way to compose my query/update a bit more elegantly than my brute force attempt above and I would be grateful if someone could enlighten me.</p>