Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Renamed CatamorphicVector (back) to LazyVector

  • Loading branch information...
commit 0c42021147ed7690a3ef655f30fb9e12ceca3c13 1 parent 99e4227
@djspiewak authored
View
6 src/main/scala/com/codecommit/antixml/GroupView.scala
@@ -28,7 +28,7 @@
package com.codecommit.antixml
-import util.CatamorphicVector
+import util.LazyVector
import javax.xml.stream.XMLStreamReader
import javax.xml.stream.XMLStreamConstants._
import scala.collection.IndexedSeqLike
@@ -37,8 +37,8 @@ class GroupNodeView private[antixml](xmlReader: XMLStreamReader) extends Indexed
override protected[this] def newBuilder = GroupView.newBuilder[NodeView]
- private val nodes: CatamorphicVector[XMLStreamReader, NodeView] = {
- val back = CatamorphicVector(xmlReader) { xmlReader =>
+ private val nodes: LazyVector[XMLStreamReader, NodeView] = {
+ val back = LazyVector(xmlReader) { xmlReader =>
if (xmlReader.hasNext) {
(xmlReader.next match {
case `START_ELEMENT` => Some(xmlReader, new ElemView(xmlReader))
View
34 ...mmit/antixml/util/CatamorphicVector.scala → .../codecommit/antixml/util/LazyVector.scala
@@ -28,7 +28,7 @@
package com.codecommit.antixml.util
-private[antixml] class CatamorphicVector[S, +A] private (
+private[antixml] class LazyVector[S, +A] private (
private[this] var _body: Vector[A],
private[this] var _tail: Vector[A],
private var state: S,
@@ -52,33 +52,33 @@ private[antixml] class CatamorphicVector[S, +A] private (
throw new IndexOutOfBoundsException(i.toString)
}
- def updated[B >: A](i: Int, b: B): CatamorphicVector[S, B] = {
+ def updated[B >: A](i: Int, b: B): LazyVector[S, B] = {
extend(i)
val body2 = if (i < body.length)
body.updated(i, b)
else
throw new IndexOutOfBoundsException(i.toString)
- new CatamorphicVector(body2, tail, state, f)
+ new LazyVector(body2, tail, state, f)
}
- def +:[B >: A](b: B): CatamorphicVector[S, B] =
- new CatamorphicVector(b +: body, tail, state, f)
+ def +:[B >: A](b: B): LazyVector[S, B] =
+ new LazyVector(b +: body, tail, state, f)
- def :+[B >: A](b: B): CatamorphicVector[S, B] =
- new CatamorphicVector(body, tail :+ b, state, f)
+ def :+[B >: A](b: B): LazyVector[S, B] =
+ new LazyVector(body, tail :+ b, state, f)
- def ++[B >: A](that: CatamorphicVector[S, B]): CatamorphicVector[S, B] =
- new CatamorphicVector(force ++ that.body, that.tail, that.state, that.f)
+ def ++[B >: A](that: LazyVector[S, B]): LazyVector[S, B] =
+ new LazyVector(force ++ that.body, that.tail, that.state, that.f)
- def ++[B >: A](that: Vector[B]): CatamorphicVector[S, B] =
- new CatamorphicVector(body, tail ++ that, state, f)
+ def ++[B >: A](that: Vector[B]): LazyVector[S, B] =
+ new LazyVector(body, tail ++ that, state, f)
- def map[B](f: A => B): CatamorphicVector[S, B] = {
+ def map[B](f: A => B): LazyVector[S, B] = {
val body2 = body map f
val tail2 = tail map f
val f2 = this.f andThen { _ map { case (s, a) => (s, f(a)) } }
- new CatamorphicVector(body2, tail2, state, f2)
+ new LazyVector(body2, tail2, state, f2)
}
def force: Vector[A] = {
@@ -116,10 +116,10 @@ private[antixml] class CatamorphicVector[S, +A] private (
forced.length
}
- override def toString = "CatamorphicVector(%s, %s, %s, %s)".format(body, tail, state, f)
+ override def toString = "LazyVector(%s, %s, %s, %s)".format(body, tail, state, f)
}
-private[antixml] object CatamorphicVector {
- def apply[S, A](init: S)(f: S => Option[(S, A)]): CatamorphicVector[S, A] =
- new CatamorphicVector(Vector(), Vector(), init, f)
+private[antixml] object LazyVector {
+ def apply[S, A](init: S)(f: S => Option[(S, A)]): LazyVector[S, A] =
+ new LazyVector(Vector(), Vector(), init, f)
}
View
22 ...antixml/util/CatamorphicVectorSpecs.scala → ...commit/antixml/util/LazyVectorSpecs.scala
@@ -32,30 +32,30 @@ import org.specs2.mutable._
import org.specs2.ScalaCheck
import org.scalacheck._
-class CatamorphicVectorSpecs extends Specification with ScalaCheck {
+class LazyVectorSpecs extends Specification with ScalaCheck {
import Gen._
import Prop._
lazy val numProcessors = Runtime.getRuntime.availableProcessors
implicit val params = set(workers -> numProcessors)
- def emptyVector[S, A](z: S) = CatamorphicVector[S, A](z) { (_: S) => None }
+ def emptyVector[S, A](z: S) = LazyVector[S, A](z) { (_: S) => None }
- def singletonVector[A](a: A): CatamorphicVector[Boolean, A] =
- CatamorphicVector(true) { (b: Boolean) => if (b) Some(false -> a) else None }
+ def singletonVector[A](a: A): LazyVector[Boolean, A] =
+ LazyVector(true) { (b: Boolean) => if (b) Some(false -> a) else None }
- def listToVector[A](xs: List[A]): CatamorphicVector[List[A], A] = {
- CatamorphicVector(xs) {
+ def listToVector[A](xs: List[A]): LazyVector[List[A], A] = {
+ LazyVector(xs) {
case hd :: tail => Some(tail -> hd)
case Nil => None
}
}
- "CatamorphicVector" >> {
+ "LazyVector" >> {
implicit val arbInt = Arbitrary(choose(0, 10000))
"apply should preserve the ordering of its elements" in {
- val naturals = CatamorphicVector(0) { (n: Int) => Some(n + 1 -> n) }
+ val naturals = LazyVector(0) { (n: Int) => Some(n + 1 -> n) }
check { x: Int =>
val result = naturals(x)
@@ -69,7 +69,7 @@ class CatamorphicVectorSpecs extends Specification with ScalaCheck {
}
"updated should modify the specified index (and only that index)" in {
- val naturals = CatamorphicVector(0) { (n: Int) => Some(n + 1 -> n) }
+ val naturals = LazyVector(0) { (n: Int) => Some(n + 1 -> n) }
check { x: Int =>
var naturals2 = naturals.updated(x, -42) // not a natural...
@@ -85,7 +85,7 @@ class CatamorphicVectorSpecs extends Specification with ScalaCheck {
}
}
- "prepending to empty should have the same elements as the singleton CatamorphicVector" in check { x: Int =>
+ "prepending to empty should have the same elements as the singleton LazyVector" in check { x: Int =>
(x +: emptyVector(0)).force mustEqual singletonVector(x).force
}
@@ -93,7 +93,7 @@ class CatamorphicVectorSpecs extends Specification with ScalaCheck {
(x +: emptyVector(0)).force mustEqual (emptyVector(0) :+ x).force
}
- "appending to empty should be equivalent to the singleton CatamorphicVector" in check { x: Int =>
+ "appending to empty should be equivalent to the singleton LazyVector" in check { x: Int =>
(emptyVector(0) :+ x).force mustEqual singletonVector(x).force
}
Please sign in to comment.
Something went wrong with that request. Please try again.