# Why were single-line lambdas removed?

**URL:** <https://users.scala-lang.org/t/why-were-single-line-lambdas-removed/11980>\
**Category:** Question\
**Created:** [August 14, 2025, 3:19am UTC](https://users.scala-lang.org/t/why-were-single-line-lambdas-removed/11980 "2025-08-14T03:19:20Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![codexk](https://users.scala-lang.org/letter_avatar_proxy/v4/letter/c/22d042/32.png) [@codexk](https://users.scala-lang.org/u/codexk)\
**Post date:** [August 14, 2025, 3:19am UTC](https://users.scala-lang.org/t/why-were-single-line-lambdas-removed/11980/1 "2025-08-14T03:19:20Z")

</div>

Looking through old PRs I found this [Change `fewerBraces` to support inline lambdas after `:` by odersky · Pull Request #15258 · scala/scala3 · GitHub](https://github.com/scala/scala3/pull/15258)

> odersky commented on May 21, 2022 •  
> So it’s
> 
> ```scala
> xs.map: x =>
> x + 1
> .foldLeft: (x, y) =>
> x + y
> 
> ```
> 
> Now also possible:
> 
> ```scala
> xs.map: x => x + 1
> .foldLeft: (x, y) => x + y
> 
> ```

It was possible to write `xs.map: x => x + 1`, no newline required.

This looks nice, why was it deprecated? Are there any preserved discussions I can read to understand the decision to remove it? I’m looking through related comments on github, but it’s a bit hard understanding bit-by-bit out of context. All I’ve seen is that it looks similar to type ascriptions. Was that the only reason?

---

<div class="post-metadata">

**Author:** ![spamegg1](https://users.scala-lang.org/user_avatar/users.scala-lang.org/spamegg1/32/2131_2.png) [@spamegg1](https://users.scala-lang.org/u/spamegg1)\
**Post date:** [August 14, 2025, 6:49am UTC](https://users.scala-lang.org/t/why-were-single-line-lambdas-removed/11980/2 "2025-08-14T06:49:28Z")

</div>

> [@codexk](#):
>
> It was possible to write `xs.map: x => x + 1`, no newline required.

Really? When was this? (what Scala version) I must have missed it. It was probably briefly available?

---

<div class="post-metadata">

**Author:** ![Jasper-M](https://users.scala-lang.org/user_avatar/users.scala-lang.org/jasper-m/32/872_2.png) [@Jasper-M](https://users.scala-lang.org/u/Jasper-M)\
**Post date:** [August 14, 2025, 8:01am UTC](https://users.scala-lang.org/t/why-were-single-line-lambdas-removed/11980/3 "2025-08-14T08:01:54Z")

</div>

I don’t really understand the problem with `xs.map(x => x + 1)` to be honest. Even if you hate and want to abandon all braces, parentheses are not braces…

---

<div class="post-metadata">

**Author:** ![som-snytt](https://users.scala-lang.org/letter_avatar_proxy/v4/letter/s/7cd45c/32.png) [@som-snytt](https://users.scala-lang.org/u/som-snytt)\
**Post date:** [August 14, 2025, 9:11am UTC](https://users.scala-lang.org/t/why-were-single-line-lambdas-removed/11980/4 "2025-08-14T09:11:39Z")

</div>

Odersky comment in the contributors thread, at the time of those PRs about “inline” (i.e. “one-line”) lambdas:

> **[Make "fewerBraces" available outside snapshot releases](https://contributors.scala-lang.org/t/make-fewerbraces-available-outside-snapshot-releases/5024/154?u=som-snytt)**
>
> There’s now a PR that implements the proposed scheme. Change \`fewerBraces\` to always require a \`:\`. by odersky · Pull Request #15258 · lampepfl/dotty · GitHub. While the changes to the existing syntax are small and manageable, the changes to the...

[A few posts later](https://contributors.scala-lang.org/t/make-fewerbraces-available-outside-snapshot-releases/5024/157?u=som-snytt) he says:

> In other words, `fewerBraces` is about dropping braces, not parentheses.

See previous message by Jasper-M.

[Seb comment earlier in the thread](https://contributors.scala-lang.org/t/make-fewerbraces-available-outside-snapshot-releases/5024/23?u=sjrd), which re-activated it. The PR about lambdas was about requiring colon, which was absent before, and that was the version Seb was responding to.

Besides aesthetics, the deciding factor against one-line lambdas was disambiguation, because the parser must look at the rest of the line to decide what it is. I think having lambda params on the same line is already a pretty good trick.

There is a [post asking for one-line lambda syntax](https://contributors.scala-lang.org/t/make-fewerbraces-available-outside-snapshot-releases/5024/10?u=som-snytt) near the beginning of the thread, from a year previous.

It is a rich thread well worth reading. covering pedagogy and more thoughts about significant indentation and challenges to migration. However, no conclusion was reached as to the optimal indentation width for Scala, except that it falls in the range `2..4`.

---

<div class="post-metadata">

**Author:** ![som-snytt](https://users.scala-lang.org/letter_avatar_proxy/v4/letter/s/7cd45c/32.png) [@som-snytt](https://users.scala-lang.org/u/som-snytt)\
**Post date:** [August 14, 2025, 9:26am UTC](https://users.scala-lang.org/t/why-were-single-line-lambdas-removed/11980/5 "2025-08-14T09:26:20Z")

</div>

The link is to a PR that was not merged.

When they write the simple examples, I want it.

I’m a fan of one-line catch, and I’d also like one-line match.

We know that LOC represents technical debt (for a given bug rate), so that having more constructs that encourage one-liners will necessarily reduce bugs.

The ad copy writes itself.

---

<div class="post-metadata">

**Author:** ![spamegg1](https://users.scala-lang.org/user_avatar/users.scala-lang.org/spamegg1/32/2131_2.png) [@spamegg1](https://users.scala-lang.org/u/spamegg1)\
**Post date:** [August 14, 2025, 10:14am UTC](https://users.scala-lang.org/t/why-were-single-line-lambdas-removed/11980/6 "2025-08-14T10:14:19Z")

</div>

> [@som-snytt](#):
>
> We know that LOC represents technical debt (for a given bug rate), so that having more constructs that encourage one-liners will necessarily reduce bugs.
> 
> The ad copy writes itself.

🤣

---

<div class="post-metadata">

**Author:** ![Odersky](https://users.scala-lang.org/user_avatar/users.scala-lang.org/odersky/32/3160_2.png) [@Odersky](https://users.scala-lang.org/u/Odersky)\
**Post date:** [August 14, 2025, 11:07am UTC](https://users.scala-lang.org/t/why-were-single-line-lambdas-removed/11980/7 "2025-08-14T11:07:25Z")

</div>

Single-line lambdas with `:` were never implemented. To do this we’d have to solve some ambiguity problems in the syntax which look hard. I think it might be worth trying this, but right now I have other priorities.

---

<div class="post-metadata">

**Author:** ![codexk](https://users.scala-lang.org/letter_avatar_proxy/v4/letter/c/22d042/32.png) [@codexk](https://users.scala-lang.org/u/codexk)\
**Post date:** [August 14, 2025, 5:07pm UTC](https://users.scala-lang.org/t/why-were-single-line-lambdas-removed/11980/8 "2025-08-14T17:07:27Z")

</div>

> [@Jasper-M](#):
>
> I don’t really understand the problem with `xs.map(x => x + 1)` to be honest.

There’s not a problem with that example, `xs.map: x => x + 1` and `xs.map(x => x + 1)` are equal in readability. The problem is inconsistency, it’s nice to not mix notations throughout a codebase.

---

<div class="post-metadata">

**Author:** ![charpov](https://users.scala-lang.org/user_avatar/users.scala-lang.org/charpov/32/500_2.png) [@charpov](https://users.scala-lang.org/u/charpov)\
**Post date:** [August 18, 2025, 9:26pm UTC](https://users.scala-lang.org/t/why-were-single-line-lambdas-removed/11980/9 "2025-08-18T21:26:07Z")

</div>

If I start with a one-liner, I don’t mind the parentheses, but it occasionally bites me when I go from:

```scala
XS.map: x =>
   ... // lengthy code

```

to

```scala
XS.map: x =>
   ... // shorter code

```

to

```scala
XS.map: x => ... // short code

```

and now have to add parentheses.

---

<div class="post-metadata">

**Author:** ![som-snytt](https://users.scala-lang.org/letter_avatar_proxy/v4/letter/s/7cd45c/32.png) [@som-snytt](https://users.scala-lang.org/u/som-snytt)\
**Post date:** [August 19, 2025, 2:58pm UTC](https://users.scala-lang.org/t/why-were-single-line-lambdas-removed/11980/10 "2025-08-19T14:58:28Z")

</div>

That just happened to me! This “refactoring” case was mentioned a few times in the discussions.

One may ask how often does one do that.

My experience was a line of debug, where I wanted it single-line so that I could more easily comment it out. (Without firing up an IDE to do “block commenting-out”.)

```auto
res
  .tap: v => println(v)

```

The other footnote is that one can refactor the other way:

```auto
xs.map:
  x => f(x)

```

---

<div class="post-metadata">

**Author:** ![Odersky](https://users.scala-lang.org/user_avatar/users.scala-lang.org/odersky/32/3160_2.png) [@Odersky](https://users.scala-lang.org/u/Odersky)\
**Post date:** [August 26, 2025, 10:34pm UTC](https://users.scala-lang.org/t/why-were-single-line-lambdas-removed/11980/11 "2025-08-26T22:34:11Z")

</div>

It turns out we can actually make it work: [Allow single-line lambdas after `:` by odersky · Pull Request #23821 · scala/scala3 · GitHub](https://github.com/scala/scala3/pull/23821).

---

<div class="post-metadata">

**Author:** ![Odersky](https://users.scala-lang.org/user_avatar/users.scala-lang.org/odersky/32/3160_2.png) [@Odersky](https://users.scala-lang.org/u/Odersky)\
**Post date:** [September 23, 2025, 11:56am UTC](https://users.scala-lang.org/t/why-were-single-line-lambdas-removed/11980/12 "2025-09-23T11:56:27Z")

</div>

There’s now a [Pre-SIP discussion](https://contributors.scala-lang.org/t/pre-sip-allow-single-line-lambdas-after/7258) for the new feature on Contributors.
