Using the new into

Now that into has been finalized (in the upcoming 3.9.0), I’m looking for places in my code where I would benefit from it.

My question is: Is there a danger of overusing it?

For instance, I’m looking at custom extensions I have:

extension [A](collection: IterableOnce[A])
   ...

Is there any drawback in generalizing to:

extension [A](collection: into[IterableOnce[A]])
   ...

?

given conversions to IterableOnce would enable my extensions no mater what. Using into only means it now happens without a warning. Is that bad? In short, is there a good reason not to sprinkle into all over my code for added flexibility?

2 Likes

I’m still curious about that. Is there a document somewhere that discusses possible uses (and abuses) of into?

2 Likes

I’d be a little cautious about using into everywhere. The extra flexibility is useful, but it can also make conversions less obvious and potentially hide unintended conversions. I’d mainly use it where accepting multiple input types clearly improves the API, rather than as a default for every parameter.

4 Likes