# Pattern match only in for comprehension

**URL:** <https://contributors.scala-lang.org/t/pattern-match-only-in-for-comprehension/6809>\
**Category:** Language Design\
**Created:** [November 7, 2024, 2:05pm UTC](https://contributors.scala-lang.org/t/pattern-match-only-in-for-comprehension/6809 "2024-11-07T14:05:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![OndrejSpanel](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/ondrejspanel/32/1238_2.png) [@OndrejSpanel](https://contributors.scala-lang.org/u/OndrejSpanel)\
**Post date:** [November 7, 2024, 2:05pm UTC](https://contributors.scala-lang.org/t/pattern-match-only-in-for-comprehension/6809/1 "2024-11-07T14:05:51Z")

</div>

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

```scala
        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 `<-`:

```scala
        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?
