# Scala 3 specific stdlib improvements

**URL:** <https://contributors.scala-lang.org/t/scala-3-specific-stdlib-improvements/6661>\
**Category:** Scala Standard Library\
**Created:** [May 16, 2024, 7:32am UTC](https://contributors.scala-lang.org/t/scala-3-specific-stdlib-improvements/6661 "2024-05-16T07:32:54Z")\
**Posts on this page:** 12\
**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:** [May 16, 2024, 7:32am UTC](https://contributors.scala-lang.org/t/scala-3-specific-stdlib-improvements/6661/1 "2024-05-16T07:32:54Z")

</div>

Some parts of stdlib could be greatly ehanced by using Scala 3 specific features. One example is `ChainingSyntax`. Just consider:

```auto
  extension [A](self: A):
    inline def tap[U](inline f: A => U): A =
      f(self)
      self
    inline def pipe[B](inline f: A => B): B = f(self)

```

Using `inline` here is not only more efficient, it also makes debugging more reliable (no lambdas), exception callstacks shorter and tidier and it e.g. makes `return` statemens from inside possible, as they are no longer non-local.

I am not sure what are binary compatibility concerns in cases like this and what strategy could be used to implement Scala 3 improvements to some carefully seleected parts of stdlib.

---

<div class="post-metadata">

**Author:** ![bishabosha](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/bishabosha/32/3101_2.png) [@bishabosha](https://contributors.scala-lang.org/u/bishabosha)\
**Post date:** [May 16, 2024, 7:56am UTC](https://contributors.scala-lang.org/t/scala-3-specific-stdlib-improvements/6661/2 "2024-05-16T07:56:12Z")

</div>

The current strategy is shipping some other code such as in [scala.runtime.stdLibPatches.Predef](https://github.com/scala/scala3/blob/177b48991dfebc47f7b3efdb5038735f4c491b2d/library/src/scala/runtime/stdLibPatches/Predef.scala#L1)

e.g. `assert`, `implicitly` and `locally` methods are overridden here

Then we intercept any patched definitions when we initialise the compiler and point them to the patched version

---

<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:** [May 17, 2024, 9:34am UTC](https://contributors.scala-lang.org/t/scala-3-specific-stdlib-improvements/6661/3 "2024-05-17T09:34:08Z")

</div>

Interesting, thanks. I can see `assert` there, but not `locally` or `implicitly`, only `summon`.

Who and how chooses what will be added there? Is `pipe` / `tap` a good candidate?

How many functions can be added before the maintenance burden becomes too heavy? Will Scala 3 improvements in stdlib have to wait until Scala 2.13 dies, which may be practically never?

---

<div class="post-metadata">

**Author:** ![som-snytt](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/som-snytt/32/595_2.png) [@som-snytt](https://contributors.scala-lang.org/u/som-snytt)\
**Post date:** [May 17, 2024, 2:37pm UTC](https://contributors.scala-lang.org/t/scala-3-specific-stdlib-improvements/6661/4 "2024-05-17T14:37:50Z")

</div>

SIP 51 mentions the issue without solving it.

That document is no longer new, so probably their thinking has evolved since then.

It would be great to get `@inline` `tap` under scala 2 and `inline` under scala 3.

[https://docs.scala-lang.org/sips/drop-stdlib-forwards-bin-compat.html](https://docs.scala-lang.org/sips/drop-stdlib-forwards-bin-compat.html)

---

<div class="post-metadata">

**Author:** ![bishabosha](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/bishabosha/32/3101_2.png) [@bishabosha](https://contributors.scala-lang.org/u/bishabosha)\
**Post date:** [May 21, 2024, 3:37pm UTC](https://contributors.scala-lang.org/t/scala-3-specific-stdlib-improvements/6661/5 "2024-05-21T15:37:30Z")

</div>

> [@OndrejSpanel](#):
>
> Interesting, thanks. I can see `assert` there, but not `locally` or `implicitly`, only `summon`.

Oh that is interesting, I think before 3.0.0 this was the case, but we did some “cleanup” which probably decided it was not worth patching those methods - but at least `assert` exists in the 2.13 `Predef` also

---

<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:** [May 27, 2024, 11:29am UTC](https://contributors.scala-lang.org/t/scala-3-specific-stdlib-improvements/6661/6 "2024-05-27T11:29:36Z")

</div>

@som-snytt In [Cross-build by som-snytt · Pull Request #240 · scala/scala-collection-contrib · GitHub](https://github.com/scala/scala-collection-contrib/pull/240#issuecomment-2129430839) you mentioned:

> Use of `tap` is also a test of cross-compilation. Scala 3 ought already to intercept that API to make it inline

Is this documented somewhere? When and how was it implemented?

---

<div class="post-metadata">

**Author:** ![bishabosha](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/bishabosha/32/3101_2.png) [@bishabosha](https://contributors.scala-lang.org/u/bishabosha)\
**Post date:** [May 27, 2024, 12:54pm UTC](https://contributors.scala-lang.org/t/scala-3-specific-stdlib-improvements/6661/7 "2024-05-27T12:54:53Z")

</div>

> [@OndrejSpanel](#):
>
> Is this documented somewhere? When and how was it implemented?

there is no interception of pipe and tap in scala 3

---

<div class="post-metadata">

**Author:** ![som-snytt](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/som-snytt/32/595_2.png) [@som-snytt](https://contributors.scala-lang.org/u/som-snytt)\
**Post date:** [May 27, 2024, 2:31pm UTC](https://contributors.scala-lang.org/t/scala-3-specific-stdlib-improvements/6661/8 "2024-05-27T14:31:25Z")

</div>

My comment was prescriptive, not descriptive. Or, if you like, moral imperative.

---

<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:** [August 25, 2025, 6:49am UTC](https://contributors.scala-lang.org/t/scala-3-specific-stdlib-improvements/6661/9 "2025-08-25T06:49:33Z")

</div>

I have seen several mentions on GitHub most of the stdlib will be compiled by Scala 3 compiler to allow improving it as needed, starting with 3.8 release, and its distribution will be changed a bit. I think this is great news. I guess it will be done carefully to avoid annoyance as much as possible, but still maybe this is quite a substantial change, which might deserve an announcement? Maybe next Scala Highlights could cover this?

---

<div class="post-metadata">

**Author:** ![hepin1989](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/hepin1989/32/419_2.png) [@hepin1989](https://contributors.scala-lang.org/u/hepin1989)\
**Post date:** [August 25, 2025, 8:09am UTC](https://contributors.scala-lang.org/t/scala-3-specific-stdlib-improvements/6661/10 "2025-08-25T08:09:51Z")

</div>

In Scala 3.8, it will use the stdlib in source, other than the one from Scala 2.13, but I still don’t know which features were added, may be CC checked？

---

<div class="post-metadata">

**Author:** ![thanh](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/thanh/32/2399_2.png) [@thanh](https://contributors.scala-lang.org/u/thanh)\
**Post date:** [August 25, 2025, 11:34am UTC](https://contributors.scala-lang.org/t/scala-3-specific-stdlib-improvements/6661/11 "2025-08-25T11:34:40Z")

</div>

In 3.8 standard library will be annotated with capture checking (from what I heard in scaladays), but I’m not aware of any other features.

---

<div class="post-metadata">

**Author:** ![mberndt](https://contributors.scala-lang.org/letter_avatar_proxy/v4/letter/m/d9b06d/32.png) [@mberndt](https://contributors.scala-lang.org/u/mberndt)\
**Post date:** [August 25, 2025, 12:58pm UTC](https://contributors.scala-lang.org/t/scala-3-specific-stdlib-improvements/6661/12 "2025-08-25T12:58:08Z")

</div>

I’m not sure if it’s possible, but maybe we can use the `@targetName` annotation to make these kinds of changes while not breaking backward compatibility? I. e. rename the old `pipe` implementation to something else (`legacyPipe` or whatever) but annotate it with `@targetName` so it’s still called `pipe` in the binary, then add the new macro-based implementation under the name `pipe`. this would retain binary compatibility while providing the benefits of the macro based implementation to callers compiled against a newer version of the standard library.

Note that other ecosystems already do something similar, e. g. glibc’s symbol versioning feature.
