Pattern match only in for comprehension

Would it be possible to extend for comprehension so that it accepts pattern match in alias declaration, like this?

        val sourceId = for {
          source <- action.actionSource
          case id: AsEntity = source.id
        } yield id

Currently it is necessary to wrap the value in something so that it can be extracted using <-:

        val sourceId = for {
          source <- action.actionSource
          case id: AsEntity <- Some(source.id)
        } yield id

Not bad, but not that nice either.

If this would be possible, what would it desugar to?

2 Likes