Skip to content

Commit

Permalink
removed toList from WindowBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
nathaniel-may committed Apr 22, 2019
1 parent 9579392 commit d0e6175
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# BufferedZipper
[![CircleCI](https://circleci.com/gh/nathaniel-may/BufferedZipper.svg?style=svg)](https://circleci.com/gh/nathaniel-may/BufferedZipper)
[![codecov](https://codecov.io/gh/nathaniel-may/BufferedZipper/branch/master/graph/badge.svg)](https://codecov.io/gh/nathaniel-may/BufferedZipper)



`BufferedZipper` is a data type that manages effectful buffering compatible with `cats-core` and `cats-effect`.

Expand Down
1 change: 0 additions & 1 deletion src/main/scala/zipper/WindowBuffer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ sealed trait WindowBuffer[+A] {
def ls: Vector[A] = WindowBuffer.leftsRights(this)._1
def rs: Vector[A] = WindowBuffer.leftsRights(this)._2
def contains[B >: A](b: B): Boolean = WindowBuffer.contains[A, B](this)(b)
def toList: List[A] = toVector.toList //TODO remove this because it takes an extra traversal
def toVector: Vector[A] = WindowBuffer.toVector(this)
def map[B](f: A => B): WindowBuffer[B] = this match {
case LeftEndBuffer(rs, foc, lim) => LeftEndBuffer(rs.map(f), f(foc), lim)
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/util/PropertyFunctions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object PropertyFunctions {
State.modify[Int](_ => 0).map(_ => a)

def measureBufferContents[A](buff: WindowBuffer[A]): Long =
buff.toList.map(meter.measureDeep).sum - meter.measureDeep(buff.focus)
buff.toVector.toList.map(meter.measureDeep).sum - meter.measureDeep(buff.focus)

def assertOnPath[M[_] : Monad, A](bz: BufferedZipper[M, A], path: Path, f: BufferedZipper[M, A] => Boolean): M[Boolean] =
resultsOnPath(bz, path, f).map(_.forall(identity))
Expand Down
4 changes: 2 additions & 2 deletions src/test/scala/zipper/BufferedZipperProperties.scala
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ object BufferedZipperProperties extends Properties("BufferedZipper") {
forAll(uniqueBZipGen[String](byteLimitAtLeast(16)), pathGen) {
(in: BufferedZipper[Id, String], path: Path) =>
assertOnPath[Id, String](in, path, bz =>
bz.buffer.toList.groupBy(identity).valuesIterator.forall(_.size == 1))
bz.buffer.toVector.toList.groupBy(identity).valuesIterator.forall(_.size == 1))
}

property("buffer is always a segment of the input") =
forAll(uniqueBZipGen[String](byteLimitAtLeast(16)), pathGen) {
(in: BufferedZipper[Id, String], path: Path) =>
assertOnPath[Id, String](in, path, bz =>
in.toStream.containsSlice(bz.buffer.toList))
in.toStream.containsSlice(bz.buffer.toVector.toList))
}

property("buffer never contains the focus") =
Expand Down
4 changes: 2 additions & 2 deletions src/test/scala/zipper/WindowBufferProperties.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ object WindowBufferProperties extends Properties("WindowBuffer") {

property("List and WindowBuffer.toList are the same with no buffer limit") = forAll {
(in: List[Int]) => toWindowBuffer(in, Unlimited)
.fold(in.isEmpty) { _.toList == in }
.fold(in.isEmpty) { _.toVector.toList == in }
}

property("List map f and WindowBuffer map f are the same with no buffer limit") = forAll {
(in: List[Int]) => toWindowBuffer(in, Unlimited)
.fold(in.isEmpty) { _.map(_+1).toList == in.map(_+1) }
.fold(in.isEmpty) { _.map(_+1).toVector.toList == in.map(_+1) }
}

property("never exceeds byte limit") =
Expand Down

0 comments on commit d0e6175

Please sign in to comment.