Skip to content

Add Conversion.into method #11668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 14, 2021
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Mar 9, 2021

Small upgrade to make conversions easier to use explicitly.

@SethTisue
Copy link
Member

SethTisue commented Mar 9, 2021

was as considered as the method name? (I've lost track of as's status a keyword or soft keyword, and in how many places it's used...)

@odersky
Copy link
Contributor Author

odersky commented Mar 9, 2021

I am also not sure what's the best name. I have the feeling that as is already used quite a lot for specific conversions. I originally was thinking of inject, that's another possibility. into comes from Rust.

One consideration is that the name should work well with and without a type parameter. Compare:

xs.into          xs.as         xs.inject
xs.into[C]       xs.as[C]      xs.inject[C]

I have the impression inject works best without a type parameter, into is sort of OK, but as is taking it too far.

@SethTisue
Copy link
Member

how about convert or converted?

@odersky
Copy link
Contributor Author

odersky commented Mar 10, 2021

convert would be the most obvious choice. That's often the best one, I agree.

@soronpo
Copy link
Contributor

soronpo commented Mar 10, 2021

Maybe convertTo[T] will be a little bit more clear, although more verbose.

@rjolly
Copy link
Contributor

rjolly commented Mar 10, 2021

@soronpo It doesn't work without the type parameter.

object Conversion:

extension [T](x: T)
/** `x.into[U]` converts a value `x` of type `T` to type `U` */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to change comment too

@odersky odersky merged commit 02cee1f into scala:master Mar 14, 2021
@odersky odersky deleted the add-conversion-into branch March 14, 2021 16:36
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants