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
Some useful Seq operations are deprecated on String #11676
Comments
The reason for the deprecation is that these methods don't make sense for Unicode strings in general. They could be useful for limited character sets but are almost guaranteed to lead to incorrect results when applied to arbitrary Unicode text. |
But this is also true of existing methods on String like |
I was hit by this on a lecture today when trying to do |
My main point is that this removes regularity and makes it difficult to beginners. |
I would support removing these deprecations. |
If a string is nothing more than a sequence of code units, then sliding is a perfectly sensible operation, yielding an iterator over subsequences of code units. Only when you insist it's actually a sequence of arbitrary codepoints representing characters, sliding no longer makes sense. But that's a starting position that's not enforced by the data type at all. You can only sensibly work with strings if you know what can and can't be in them, otherwise all you can do is treat them as opaque blobs of bytes. Its up to the user to know whether they can do something else with them (and what). |
Let's ditch
This might make a good lint, and an illustration where a lint is preferred to deprecation. Indeed, where a scalafix lint (opt-in) is preferable to an |
I've made a bold undeprecation in this PR: scala/scala#9246 |
Fixed in scala/scala#9246 |
A bunch of operations have been deprecated on
String
, although they make perfect sense there. I’m missing the reason for such deprecations. The suggestion in the deprecation message is often awkward and inefficient (eg, “Uses.toSeq.groupBy(...).view.mapValues(_.unwrap).toMap
instead ofs.groupBy(...)
”).I think that it should be possible to provide an efficient implementation for all these operations. The work can be done in separate PRs, though. Here is the list of operations:
diff
intersect
distinct
distinctBy
sorted
sortWith
sortBy
groupBy
sliding
combinations
permutations
The text was updated successfully, but these errors were encountered: