Skip to content

Cannot shuffle a Range, but can shuffle Range.Inclusive #11875

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

Closed
mbuzdalov opened this issue Jan 31, 2020 · 6 comments
Closed

Cannot shuffle a Range, but can shuffle Range.Inclusive #11875

mbuzdalov opened this issue Jan 31, 2020 · 6 comments

Comments

@mbuzdalov
Copy link

Scala 2.12.10:

scala> scala.util.Random.shuffle(1 to 10)
res0: scala.collection.immutable.IndexedSeq[Int] = Vector(8, 4, 7, 6, 3, 5, 10, 9, 1, 2)

scala> scala.util.Random.shuffle(1 until 10)
<console>:12: error: Cannot construct a collection of type scala.collection.AbstractSeq[Int] with elements of type Int based on a collection of type scala.collection.AbstractSeq[Int].
       scala.util.Random.shuffle(1 until 10)

Scala 2.13.1:

scala> scala.util.Random.shuffle(1 to 10)
res0: IndexedSeq[Int] = Vector(2, 8, 3, 7, 10, 6, 5, 4, 1, 9)

scala> scala.util.Random.shuffle(1 until 10)
                                ^
       error: Cannot construct a collection of type C with elements of type Int based on a collection of type scala.collection.immutable.Range.

There is definitely something wrong.

@lrytz
Copy link
Member

lrytz commented Jan 31, 2020

scala> implicitly[scala.collection.BuildFrom[Range.Inclusive, Int, _]]
val res5: scala.collection.BuildFrom[Range.Inclusive,Int,Any] = scala.collection.BuildFromLowPriority2$$anon$11@64b70f41

scala> implicitly[scala.collection.BuildFrom[Range, Int, _]]
                 ^
       error: Cannot construct a collection of type Any with elements of type Int based on a collection of type scala.collection.immutable.Range.

@SethTisue SethTisue added this to the Backlog milestone Jan 31, 2020
@ausmarton
Copy link

I'm new to this dev community and found this issue interesting. As I was trying to understand the issue, I realised that untils return type is an abstract class while tos return type is a concrete type Range.Inclusive.

Would changing the return type of until to Range.Exclusive here be a step in the right direction?

def until(end: Int): Range.Exclusive = Range(self, end)

@som-snytt
Copy link

#8569
#6948

@ausmarton
Copy link

Thanks @som-snytt, should we close this issue given it's duplicate of #6948?

@dwijnand
Copy link
Member

dwijnand commented Feb 2, 2020

Yeah, I think so, following #8569's lead.

@dwijnand dwijnand closed this as completed Feb 2, 2020
@dwijnand
Copy link
Member

dwijnand commented Feb 2, 2020

Duplicate of #6948

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants