Details

      Description

      Ok:

      val s = Seq(1)
      val f = (s /: Seq(99))((s,c) => s.patch(0,Seq(c),1))
      

      Won't compile:

      val s = Seq(1).view
      val f = (s /: Seq(99))((s,c) => s.patch(0,Seq(c),1))
      // error: type mismatch;
      // found   : scala.collection.SeqView[Int,Seq[_]]
      // required: java.lang.Object with scala.collection.SeqView[Int,Seq[Int]]
      //       val f = (s /: Seq(99))((s,c) => s.patch(0,Seq(c),1))
      //                                              ^
      

      Will compile, but weird results?

      val s = Seq(1).view.asInstanceOf[Seq[Int]]
      val f = (s /: Seq(99))((s,c) => s.patch(0,Seq(c),1))
      f.length == f.toList.length  //  false???  1 == 2
      

        Activity

        Hide
        Oleg Aleshko added a comment -

        also

        scala> Vector(1).view.updated(0,2).toList
        res21: List[Int] = List(2, 1)
        
        Show
        Oleg Aleshko added a comment - also scala> Vector(1).view.updated(0,2).toList res21: List[Int] = List(2, 1)
        Hide
        Josh Suereth added a comment -

        I've isolated this to a faulty iterator.

        I think it's relative to this line: override def iterator: Iterator[B] = self.iterator patch (from, patch.iterator, replaced)

        You can see an example here:

        scala> val view = Vector(1).view.updated(0,2)
        view: scala.collection.SeqView[Int,Seq[_]] = SeqViewP(...)
        
        scala> view(0)
        res25: Int = 2
        
        scala> view(1)
        java.lang.IndexOutOfBoundsException: 1
        	...
        
        
        scala> view.length
        res27: Int = 1
        
        scala> view.iterator.toList
        res28: List[Int] = List(2, 1)
        
        Show
        Josh Suereth added a comment - I've isolated this to a faulty iterator. I think it's relative to this line: override def iterator: Iterator [B] = self.iterator patch (from, patch.iterator, replaced) You can see an example here: scala> val view = Vector(1).view.updated(0,2) view: scala.collection.SeqView[Int,Seq[_]] = SeqViewP(...) scala> view(0) res25: Int = 2 scala> view(1) java.lang.IndexOutOfBoundsException: 1 ... scala> view.length res27: Int = 1 scala> view.iterator.toList res28: List[Int] = List(2, 1)
        Hide
        Josh Suereth added a comment -

        Yep, iterator.patch is broken when "from = 0". I think I have fix.

        Show
        Josh Suereth added a comment - Yep, iterator.patch is broken when "from = 0". I think I have fix.
        Hide
        Arya Irani added a comment -

        Thanks Josh!

        Show
        Arya Irani added a comment - Thanks Josh!

          People

          • Assignee:
            Josh Suereth
            Reporter:
            Arya Irani
          • Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development