SLC: make .to(IArray) work for collections

If you want to convert data to an IArray, code like the following is currently not possible:

def example = collection.view.map(_ * 2).to(IArray)

currently, you can only use the direct factory methods:

  • IArray.from(collection)
  • IArray(collection*)

implementation here: Add implicit conversion from IArray.type to Factory by bishabosha · Pull Request #24675 · scala/scala3 · GitHub

question remains if this is good enough, or if we want to also add .toIArray variants wherever .toArray exists. - perhaps this is overkill if in a couple years separationChecking can land with frozen mutability for Array (making IArray redundant)

I think adding toIArray would be overkill even if you don’t make the separation checking argument. to(IArray) is fine.

We have very few such methods that name specific collection implementations — just toVector, toList, and toArray. All of them are technically redundant with their .to(X) forms, and it’s possible we wouldn’t even introduce any of them today if they didn’t already exist. So let’s not add more, especially since I don’t see IArray being used a ton in the wild.

2 Likes