Scala Programming Language
  1. Scala Programming Language
  2. SI-4190

mutable.IndexedSeq.view.map returns collection.SeqView

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: Scala 2.11.1-RC1
    • Component/s: Collections
    • Labels:
      None

      Description

      === What steps will reproduce the problem (please be specific and use wikiformatting)? ===

      import collection.mutable._
      
      val x: ArrayBuffer[String] = ArrayBuffer("a", "b", "c")
      val y: IndexedSeq[String] = x.view map (_ + "0")
      

      This code compiles but produces a `ClassCastException` in the last line:

      java.lang.ClassCastException: scala.collection.SeqViewLike$$$$anon$$3 cannot be cast to scala.collection.mutable.IndexedSeq
      

      === What is the expected behavior? ===
      A compiler error or working code.

      === What versions of the following are you using? ===

      • Scala: 2.8.1

        Activity

        Hide
        Johannes Rudolph added a comment -

        Are you really losing the "Indexed"-ness when mapping? If the function used with `map` is slow, accessing an element will be slow afterwards as well (because you are (re)calculating that entry) but that's the usual trade-off for using views. You may lose it for other transformations but in particular for `map` I don't necessarily think so.

        Show
        Johannes Rudolph added a comment - Are you really losing the "Indexed"-ness when mapping? If the function used with `map` is slow, accessing an element will be slow afterwards as well (because you are (re)calculating that entry) but that's the usual trade-off for using views. You may lose it for other transformations but in particular for `map` I don't necessarily think so.
        Hide
        Josh Suereth added a comment -

        You're not just loosing the IndexedSeq-ness (remember Seq has indexed operations for slower indexing), you're also losing mutability of the original collection. You can't allow the view to chain mutation back into the original.

        SO yes. You're no longer a mutable.IndexedSeq after a map/flatMap/etc.

        Show
        Josh Suereth added a comment - You're not just loosing the IndexedSeq-ness (remember Seq has indexed operations for slower indexing), you're also losing mutability of the original collection. You can't allow the view to chain mutation back into the original. SO yes. You're no longer a mutable.IndexedSeq after a map/flatMap/etc.
        Hide
        Johannes Rudolph added a comment -

        Oh yes, you are clearly right about mutability, I've forgot that. Maybe I could argue if it was about immutable.IndexedSeq but as you said since it has all the methods of Seq all of this discussion is only of theoretic relevance if at all. Sorry for the noise.

        Show
        Johannes Rudolph added a comment - Oh yes, you are clearly right about mutability, I've forgot that. Maybe I could argue if it was about immutable.IndexedSeq but as you said since it has all the methods of Seq all of this discussion is only of theoretic relevance if at all. Sorry for the noise.
        Hide
        James Iry added a comment -

        2.10.2 is about to be cut. Kicking down the road and un-assigning to foster work stealing.

        Show
        James Iry added a comment - 2.10.2 is about to be cut. Kicking down the road and un-assigning to foster work stealing.
        Hide
        Adriaan Moors added a comment -

        Since 2.11.0-RC1 is one week away, pushing all non-blockers without PR to 2.11.1-RC1. Please undo the change if I missed work in progress.

        Show
        Adriaan Moors added a comment - Since 2.11.0-RC1 is one week away, pushing all non-blockers without PR to 2.11.1-RC1. Please undo the change if I missed work in progress.

          People

          • Assignee:
            Rex Kerr
            Reporter:
            Johannes Rudolph
            TracCC:
            Ismael Juma
          • Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

            • Created:
              Updated:

              Development