# Standard Library: Now open for improvements and suggestions!

**URL:** <https://contributors.scala-lang.org/t/standard-library-now-open-for-improvements-and-suggestions/7337>\
**Category:** Scala Standard Library\
**Created:** [January 12, 2026, 9:13am UTC](https://contributors.scala-lang.org/t/standard-library-now-open-for-improvements-and-suggestions/7337 "2026-01-12T09:13:36Z")\
**Posts on this page:** 20\
**Page:** 7

<div class="post-metadata">

**Author:** ![nikitaga](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/nikitaga/32/2367_2.png) [@nikitaga](https://contributors.scala-lang.org/u/nikitaga)\
**Post date:** [February 19, 2026, 5:07am UTC](https://contributors.scala-lang.org/t/standard-library-now-open-for-improvements-and-suggestions/7337/122 "2026-02-19T05:07:43Z")

</div>

If Scala `Future` is half-baked, it should be full-baked rather than dropped IMO. At least right now we can write fairly reasonable async code in plain Scala. This is table stakes, we shouldn’t _need_ third party / external libraries for this.

---

<div class="post-metadata">

**Author:** ![Quafadas](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/quafadas/32/3268_2.png) [@Quafadas](https://contributors.scala-lang.org/u/Quafadas)\
**Post date:** [February 20, 2026, 10:53pm UTC](https://contributors.scala-lang.org/t/standard-library-now-open-for-improvements-and-suggestions/7337/123 "2026-02-20T22:53:57Z")

</div>

I’d like to float a proposal — perhaps easy to dismiss — but potentially worth discussion.

Scala collections are optimized around a difficult multidimensional tradeoff: genericity, uniform APIs, abstraction quality, maintainability, and reasonable performance across many use cases.

What I’m wondering is whether there is room in the ecosystem for something at a very different point in that design space: a deliberately data-oriented, minimally abstract collection that explicitly commits to a flat, contiguous, unboxed memory layout — going all in on one axis (raw hardware efficiency) and accepting the significant constraints that follow.

Concretely, the idea would be a collection for which the compiler can guarantee:

- A single contiguous allocation

- No reference elements

- No boxing

- No structural indirection during traversal

The motivation: modern performance seems to be about memory layout - far more than algorithmic complexity. A flat, contiguous layout maximizes cache locality, enables hardware prefetching, and has potential opportunities for SIMD / loop fusion optimisations.

Such a collection would come with severe constraints?

- Primitives (or future JVM value types) only

- No references

- Limited or no polymorphism

- Possibly a different API shape to better support fusion and SIMD-friendly traversal

- Potentially fixed-size, or size changes requiring explicit reallocation

This is not be general-purpose — deliberately so. It would target a narrow, performance-sensitive niche.

`Array` already provides contiguous storage for primitives. But it doesn’t make layout guarantees explicit at the abstraction level, nor does it explore what an intentionally data-oriented API might look like — particularly in a future™ if JVM value types (Project Valhalla) were to become available.

Summarised :

> Is `Array` (plus libraries) already the correct and sufficient answer for this niche?
> 
> Or is there space for a consciously layout-committing, value-class-ready collection in Scala?

I’m genuinely unsure whether this is implementable or even desirable — but I am at least curious about the discussion if it provokes one!

---

<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:** [February 21, 2026, 10:57am UTC](https://contributors.scala-lang.org/t/standard-library-now-open-for-improvements-and-suggestions/7337/124 "2026-02-21T10:57:26Z")

</div>

You are looking for struct of arrays? this is a pretty hard problem with the primitive operations offered by the java platform - without waiting for Valhalla at least, every access would need some sort of decoder to read a value out (copy), theres no such thing as “reinterpret this slice of bytes as type X”

however yeah like you say if you only have primitive fields and you dont try to read out rows, but instead only act on columns then I think there is a space

---

<div class="post-metadata">

**Author:** ![Ichoran](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/ichoran/32/40_2.png) [@Ichoran](https://contributors.scala-lang.org/u/Ichoran)\
**Post date:** [February 21, 2026, 6:49pm UTC](https://contributors.scala-lang.org/t/standard-library-now-open-for-improvements-and-suggestions/7337/125 "2026-02-21T18:49:30Z")

</div>

I think as you’ve described it, this has to wait for Project Valhalla to finally finish, in whatever form it manages to exist in. I think it is very likely that it will have to be fixed-size to work well, so basically arrays; even if it works, size-adjustment is probably _mostly_ going to be full of performance gotchas, so one would probably want to do it intentionally for a high-performance-by-default API.

In the meantime, we could come up with a library that allows the kind of power and flexibility, without boxing, that one would like to have in an array library, and eventually extend it to an array-of-struct format where the structs were flat in memory; and it might at some point be worth adding inline tuples to the compiler, the idea being that they are never actually instantiated and can be decoupled in macro processing; this would make struct-of-arrays-accessed-like-array-of-structs a possibility.

I already have one possibility for bare-array processing in kse3, which works by making most operations inline so they can be unboxed. Thus, if you have

```scala
val xs = Array(1, 2, 3, 4, 5)

val ys = xs.drop(1).zipWithIndex.map{ case (x, i) => x / (i + 1.0) }
val zs = xs.selectOp(1 to End){ (x, i) => x / i.toDouble }

```

in the `ys` former case in Scala you duplicate the array, box everything and create an object and put that into another array, and then unbox and rebox and unbox again to put into the final array. In the latter case you act direct on the range of elements with no boxing, and just create a new primitive array directly.

Obviously I chose an example that is a bit extreme, but the point is that we can do the work to create high-efficiency high-level operations on arrays _now_, even if it doesn’t have as big a win for classes, and then if the JVM people ever get the low-level support there, we have a nice API to build from.

I write high-performance code all the time, and not having to manually write while loops and worry about corner cases all the time is really valuable. And with proper inlining, the overhead is usually either zero or quite small.

Note that the way I’ve done it is extensions on regular arrays. One could also make an opaque type around regular arrays, and then one wouldn’t have to re-invent method names (for instance, I can’t “map”, I have to “copyWith”) for the same/similar operations. For me, just-change-the-name was the easier path to what I needed. For the library, having a separate class or two might be worth the extra effort, especially if compiler people were willing to fix spots where there were performance implications due to cruft being left in the bytecode (which sometimes happens when things are inlined).

---

<div class="post-metadata">

**Author:** ![Quafadas](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/quafadas/32/3268_2.png) [@Quafadas](https://contributors.scala-lang.org/u/Quafadas)\
**Post date:** [February 22, 2026, 11:16am UTC](https://contributors.scala-lang.org/t/standard-library-now-open-for-improvements-and-suggestions/7337/126 "2026-02-22T11:16:16Z")

</div>

I think I am asking about an array of Structs, but clear note: suggesting to casually reproduce the decade or so of research in Valhalla, is obviously not a reasonable position :-).

So I agree, that my questions are probably only valid in a post valhalla world, and should perhaps be interpreted in the context of asking whether the existing collections are the optimal ones for it and / or how they might differ from the status quo?

@Ichoran answer below goes in this direction, and I think starts exploring the discussion I hoped to provoke…

So thank you both for the clarifications / answers.

---

<div class="post-metadata">

**Author:** ![JD557](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/jd557/32/3004_2.png) [@JD557](https://contributors.scala-lang.org/u/JD557)\
**Post date:** [February 22, 2026, 4:38pm UTC](https://contributors.scala-lang.org/t/standard-library-now-open-for-improvements-and-suggestions/7337/127 "2026-02-22T16:38:03Z")

</div>

On this note (however unrelated to SoA vs AoS), if the stdlib decides to provide an unboxed high performance data structure, I wonder if it would also be worth it to implement miniboxed tuples.

E.g.

```scala
opaque type TupleII = Long // Miniboxed (Int, Int)

extension (tup: TupleII) {
  def _1: Int = ((tup >> 32) & 0xffff).toInt
  def _2: Int = (tup & 0xffff).toInt
}

object TupleII {
  def apply(x: Int, y: Int): TupleII = (x.toLong << 32) | y.toLong
  def unapply(tup: TupleII): Some[(Int, Int)] = Some((tup._1, tup._2))
}

```

This seems like a simple problem for a library, but one can quickly get in the weeds regarding things like data alignment, autoderivation (maybe it should be possible to have an `UnboxedTuple2[UnboxedTuple2[Byte, Byte], Int]`) and the like.

So after a certain point, maybe it would make things easier if there was a common interface for all libraries.

Again, not sure if this would make sense in the stdlib (probably not), just some food for thought in case there’s interest in adding some high performance unboxed collections.

---

<div class="post-metadata">

**Author:** ![ragnar](https://contributors.scala-lang.org/letter_avatar_proxy/v4/letter/r/e79b87/32.png) [@ragnar](https://contributors.scala-lang.org/u/ragnar)\
**Post date:** [February 22, 2026, 10:24pm UTC](https://contributors.scala-lang.org/t/standard-library-now-open-for-improvements-and-suggestions/7337/128 "2026-02-22T22:24:24Z")

</div>

There are memory layouts, which are meant of this usecase as far as I understand.  
[Memory Layouts and Structured Access](https://docs.oracle.com/en/java/javase//21/core/memory-layouts-and-structured-access.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:** [February 23, 2026, 8:07am UTC](https://contributors.scala-lang.org/t/standard-library-now-open-for-improvements-and-suggestions/7337/129 "2026-02-23T08:07:05Z")

</div>

> [@ragnar](#):
>
> There are memory layouts, which are meant of this usecase as far as I understand.  
> [Memory Layouts and Structured Access](https://docs.oracle.com/en/java/javase//21/core/memory-layouts-and-structured-access.html)

This is a bit of a tricky problem to have automatic support for - or at least any layout must be stored as a Java `static final` field to be optimised → so with the user manually declaring some “derived” instances of a shape perhaps this can work with automation.

---

<div class="post-metadata">

**Author:** ![TRoland](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/troland/32/2471_2.png) [@TRoland](https://contributors.scala-lang.org/u/TRoland)\
**Post date:** [February 23, 2026, 10:22am UTC](https://contributors.scala-lang.org/t/standard-library-now-open-for-improvements-and-suggestions/7337/130 "2026-02-23T10:22:57Z")

</div>

Since we’re talking about allowing breaking API changes, I have a tentative wish for what I _would_ like, but I appreciate that it comes with downsides that may make this unfeasible.

**What:**

Safe operations as the canonical default, explicit unsafety opt-in; inverting the current pattern of naming so option-returning methods are the canonical methods, and `throw`ing methods get the explicit names; this should push early learners (and experienced practitioners) to use a safe-by-default coding style, eliminating common runtime errors.

**How:**

Currently, we have methods throughout Scala that return or throw; the prime example being `head` that return `A` or throw a runtime exception; we then have `headOption` to offer a safe alternative. In an ideal world, without the legacy of what we already have had for years and years, I would have preferred this to be inverted; `head` should return `Option[A]` and then we might have a `unsafeHead: A` - or even denying that existing in the first place, and forcing people to `.getOrElse(throw new …)`/ `headOrThrow`.

The collections API is probably the main place where I want this, but generically I would wish for this in places where logic errors result in `throw`n exceptions. That does not extend to stuff like e.g. I/O errors where the error isn’t inherently a logic-flaw (as such).

**My own arguments against this:**

- “ease-of-use-even-if-it-means-footguns” methods for early learners of a language may be desirable; even if it means sacrificing safety-first principles.
- We have a long history of Scala, and all example code would stop working with this backwards breaking change to what we could dub the original sin of these methods not being safe-by-default initially - we break “copy/pasting” of decade(s) of code.
- 100% adherence to never throwing becomes an exercise in reductio-ad-absurdum; math operators, overflows, division, etc probably _shouldn’t_ be safe-by-default in the same manner

**My own arguments for this:**

- The migration could be automated via compiler (no need to get scalafix involved) - 3.x uses `.head` could be rewritten into `.unsafeHead` in 3.y
- Aligns the default API to encourage (what I believe to be) idiomatic modern Scala -where `Option` is already the expected tool for absent values
- We move an issue to a compile time issue, and while a programmer can still cause a logic issue by using of `.getOrElse`, I believe core point of Scala’s type system is that the compiler helps direct us via forcing us to perform exhaustivity checks - the fact that `Option[A]` and `A` are different types. You literally cannot pass a `Option[String]` where a `String` is expected without doing something explicit; this is categorically different from an exception that silently lurks.
- This conforms to the principle of least surprises (runtime exceptions are always surprising)
- Unsafe throwing variants get an explicit ‘unsafe’ in their name, and scala doc saying why - softly directing towards a style of coding that is **safe by default**

**A tentative step towards safety:**  
Nothing stops us adding `headOrThrow` style methods now as a stepping stone, which is something the unfrozen stdlib can actually deliver without (much?) controversy - a purely additive change. Arguably we could then deprecate `head` - but, again, maybe that is, for the reasons stated above, still too controversial.

**On the whole:**  
I personally think the tradeoffs are worth it, but I understand that the drawbacks may be considerable and that the ship simply has sailed for legacy reasons. In a “redoing-the-api-from-scratch” world, that is, however, what I’d like, so I’m putting the suggestion here regardless.

---

<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:** [February 24, 2026, 9:04pm UTC](https://contributors.scala-lang.org/t/standard-library-now-open-for-improvements-and-suggestions/7337/131 "2026-02-24T21:04:22Z")

</div>

Scala 2-specific inference problems with `foreach[U]`:

> <https://github.com/scala/bug/issues/11769>
>
> Not sure if this is a bug or an expected behavior. 
> Scala 2.12. The following c…ode
> \`\`\`scala
> val mapBuilder = Map.newBuilder\[String, String\]
> val setBuilder = Set.newBuilder\[String\]
> 
> List(Option("")).foreach {
> case Some(\_) =\> mapBuilder += "" -\> ""
> case None =\> setBuilder += ""
> }
> \`\`\`
> does not compile - compiler fails to infer the least upper bound of the two builders (the \`U\` in \`foreach\[U\](f: A =\> U)\`): 
> \`\`\`
> type arguments \[String,Iterable\[java.io.Serializable\] with String =\> Any with scala.collection.generic.Subtractable\[String,Equals\]\] do not conform to trait Subtractable's type parameter bounds \[A,+Repr \<: scala.collection.generic.Subtractable\[A,Repr\]\]
> \`\`\`
> 
> Annotating the \`foreach\` with \`Any\` resolves the problem:
> \`\`\`scala
> List(Option("")).foreach\[Any\] {
> ...
> \`\`\`
> Is this an expected behavior?

I prefer the formulation in [Subtractable nightmare](https://github.com/scala/bug/issues/10151).

This is related to a question posted today about type inference; but maybe the question is more about how method signatures could be improved to cope with inference.

Maybe that falls under

> [@SethTisue](#):
>
> (The backwards bincompat constraint is something we should probably have highlighted from the start.)

---

<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:** [February 27, 2026, 1:31pm UTC](https://contributors.scala-lang.org/t/standard-library-now-open-for-improvements-and-suggestions/7337/132 "2026-02-27T13:31:05Z")

</div>

We just released Steps 0.2.0 which has some improvements to the `Result` API, please try it out and github issues are open for feedback

> **[Release 0.2.0 · lampepfl/steps](https://github.com/lampepfl/steps/releases/tag/v0.2.0)**
>
> Steps 0.2.0 requires Scala 3.8.x and Java 17.
> In this release we made improvements to the Result API:
> 
> capture checked API
> fixed a bug with the exists method, added aliases isOkAnd (for exists), is...

---

<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:** [March 23, 2026, 3:49pm UTC](https://contributors.scala-lang.org/t/standard-library-now-open-for-improvements-and-suggestions/7337/133 "2026-03-23T15:49:58Z")

</div>

We have a new blog post to announce the completion of porting the Scala 2 optimizer to Scala 3 (available in 3.8.3-RC3) - when activated it can help improve performance of programs using the new standard library: [Porting the Scala 2 optimizer to Scala 3 | The Scala Programming Language](https://www.scala-lang.org/blog/2026/03/23/porting-the-optimizer.html)

Thanks to Solal Pirelli for all the hard work!

---

<div class="post-metadata">

**Author:** ![scalafan](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/scalafan/32/3367_2.png) [@scalafan](https://contributors.scala-lang.org/u/scalafan)\
**Post date:** [April 12, 2026, 3:17pm UTC](https://contributors.scala-lang.org/t/standard-library-now-open-for-improvements-and-suggestions/7337/134 "2026-04-12T15:17:05Z")

</div>

Did someone already suggest strict versions of `mapValues` and `filterKeys`, as they are very common operations:

```auto
[warn] 58 | val sizeFrequencies = m.mapValues(_.size).mkString(", ")
[warn] | ^^^^^^^^^^^
[warn] |method mapValues in trait MapOps is deprecated since 2.13.0: Use .view.mapValues(f). A future version will include a strict version of this method (for now, .view.mapValues(f).toMap).

```

---

<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:** [April 12, 2026, 6:44pm UTC](https://contributors.scala-lang.org/t/standard-library-now-open-for-improvements-and-suggestions/7337/135 "2026-04-12T18:44:24Z")

</div>

> [@bishabosha](#):
>
> Porting the Scala 2 optimizer to Scala 3 | The Scala Programming Language

does the @inline works on Scala 3 too now?

---

<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:** [April 12, 2026, 8:04pm UTC](https://contributors.scala-lang.org/t/standard-library-now-open-for-improvements-and-suggestions/7337/136 "2026-04-12T20:04:01Z")

</div>

The post says:

> You can override the heuristics with `@inline` and `@noinline` annotations, but these should be a last-resort solution that you re-evaluate frequently as the compiler and the JVM improve.

That sounds like the same as Scala 2: the annotation is not needed and not recommended (for most use cases).

Another question is whether there is a reason to use `@inline` instead of `inline`. That is, when is optimizing a good idea if principled inlining is not?

---

<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:** [April 13, 2026, 5:18am UTC](https://contributors.scala-lang.org/t/standard-library-now-open-for-improvements-and-suggestions/7337/137 "2026-04-13T05:18:03Z")

</div>

Yes, because in projects like pekko / sjsonnet, then we have to split the code for scala 3 and scala 2 to leverage the inline optimizer.

---

<div class="post-metadata">

**Author:** ![eshu](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/eshu/32/2137_2.png) [@eshu](https://contributors.scala-lang.org/u/eshu)\
**Post date:** [April 13, 2026, 7:43am UTC](https://contributors.scala-lang.org/t/standard-library-now-open-for-improvements-and-suggestions/7337/138 "2026-04-13T07:43:47Z")

</div>

```auto
final case class Left[+A](value: A) extends Either[A, Nothing]

final case class Right[+B](value: B) extends Either[Nothing, B]

```

---

<div class="post-metadata">

**Author:** ![kai](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/kai/32/1733_2.png) [@kai](https://contributors.scala-lang.org/u/kai)\
**Post date:** [April 20, 2026, 12:43am UTC](https://contributors.scala-lang.org/t/standard-library-now-open-for-improvements-and-suggestions/7337/139 "2026-04-20T00:43:12Z")

</div>

> [@Ichoran](#):
>
> If done sequentially, you can update a variable that is captured by the closure for the map.

`mapAccum` is sorely missing from the stdlib – that and `flatTraverse` are the only two collection operators I use from cats frequently.

> [@TRoland](#):
>
> I would have preferred this to be inverted; `head` should return `Option[A]` and then we might have a `unsafeHead: A`.

Note: this change can be made both without breaking binary compatibility and without special support from the compiler, by using `targetName` to assign the old binary name to `headOrThrow`: `@targetName("head") def headOrThrow: A; def head: Option[A]` - new `head` doesn’t need a targetName rename because the methods have distinct return types `Object` and `Option`.

> [@eshu](#):
>
> ```auto
> final case class Left[+A](value: A) extends Either[A, Nothing]
> 
> final case class Right[+B](value: B) extends Either[Nothing, B]
> 
> ```

👍 This is long overdue and involves no risk of binary breakage.

---

<div class="post-metadata">

**Author:** ![halotukozak](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/halotukozak/32/3217_2.png) [@halotukozak](https://contributors.scala-lang.org/u/halotukozak)\
**Post date:** [April 21, 2026, 3:09pm UTC](https://contributors.scala-lang.org/t/standard-library-now-open-for-improvements-and-suggestions/7337/140 "2026-04-21T15:09:53Z")

</div>

Could we make `Array.tabulate` and related methods inlined? This would prevent the function objects allocation, similar to how it’s done in Kotlin

---

<div class="post-metadata">

**Author:** ![scalafan](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/scalafan/32/3367_2.png) [@scalafan](https://contributors.scala-lang.org/u/scalafan)\
**Post date:** [June 7, 2026, 4:28am UTC](https://contributors.scala-lang.org/t/standard-library-now-open-for-improvements-and-suggestions/7337/141 "2026-06-07T04:28:08Z")

</div>

Let’s make `List` less central to the collections.

Saying what needs to be said, `List` is probably the worst data structure to ever use. On modern CPUs and the cache structure, constantly jumping around to different memory addresses is pretty much the worst thing you can do. The memory use is also pretty high, in respect to object headers, object pointers and object memory alignment. When project Valhalla lands, this performance discrepancy will become even worse compared to `Vector`, for example.

In my personal experience, `List` is the best choice only in highly branching recursive algorithms. Moreover, I used to use it for mutable fields, which resulted in many of my sequences to be unnaturally reversed (because only prepend is efficient, and not append), leading to bugs.

I am proposing:

1. Change default implementation of `Seq` to be something else. Or shorten the name of `IndexedSeq` so people will use it more instead.
2. Shorten names for `Vector` and `ArraySeq` to something 3 or 4 letters. Especially `ArraySeq`, it is pain to read and type. Also, import it into predef by default.
3. Maybe add a version of `List` where append is efficient, and prepend is not.

What do you think?

[Previous page](https://contributors.scala-lang.org/t/standard-library-now-open-for-improvements-and-suggestions/7337.md?page=6)

[Next page](https://contributors.scala-lang.org/t/standard-library-now-open-for-improvements-and-suggestions/7337.md?page=8)
