Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9161261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:55:44+00:00 2026-06-17T13:55:44+00:00

The following scala code compiles fine. object Main extends App { import scala.collection.mutable.IndexedSeq def

  • 0

The following scala code compiles fine.

object Main extends App {
  import scala.collection.mutable.IndexedSeq

  def doIt() {
    val nums: IndexedSeq[Int] = Array(3,5,9,11)
    val view: IndexedSeq[Int] = nums.view
    val half: IndexedSeq[Int] = view.take(2)
    val grouped: Iterator[IndexedSeq[Int]] = half.grouped(2)
    val firstPair: IndexedSeq[Int] = grouped.next() //throws exception here
  }

  doIt()
}

However, at runtime it thows java.lang.ClassCastException: scala.collection.SeqViewLike$$anon$1 cannot be cast to scala.collection.mutable.IndexedSeq
on the call grouped.next()

I would expect the call to grouped.next() to return something equal to IndexedSeq[Int](3,5)

I am wondering why is this code failing, and if there a proper way to fix it?

If I repeat the same steps in the REPL, the type information confirms why the code compiles, but does not give me any insight to why the exception was thrown:

scala> val nums = Array(3,5,9,11)
nums: Array[Int] = Array(3, 5, 9, 11)

scala> val view = nums.view
view: scala.collection.mutable.IndexedSeqView[Int,Array[Int]] = SeqView(...)

scala> val half = view.take(2)
half: scala.collection.mutable.IndexedSeqView[Int,Array[Int]] = SeqViewS(...)

scala> val grouped = half.grouped(2)
grouped: Iterator[scala.collection.mutable.IndexedSeqView[Int,Array[Int]]] = non-empty iterator

scala> val firstPair = grouped.next()
java.lang.ClassCastException: scala.collection.SeqViewLike$$anon$1 cannot be cast to scala.collection.mutable.IndexedSeqView

Scala version 2.10.0-20121205-235900-18481cef9b — Copyright 2002-2012, LAMP/EPFL

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:55:45+00:00Added an answer on June 17, 2026 at 1:55 pm

    Looks like you ran into bug SI-6709

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't know why the following scala code can not be compiled: import collection.immutable.Seq
Consider the following Scala code: package scala_java object MyScala { def setFunc(func: Int =>
On compiling the following code with Scala 2.7.3, package spoj object Prime1 { def
For the following code: package FileOperations import java.net.URL object FileOperations { def processWindowsPath(p: String):
I'm running the following Scala code. It compiles a single display list of 10,000
In Scala IDE I have the following code: package pkg.one object S { class
Say I have following code: object ForComprehension { def generateSomeSeq(n: Int): List[Int] = (1
The following Scala code works fine in Scala 2.9, but it generates compiler error
Consider the following typical Scala 'pimp' code: class PimpedA(a:A){ def pimp() = hi }
Suppose I have the following Scala code: class Foo(a: Int) class Bar(b: Buffer[Int]) extends

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.