Skip to content

Commit

Permalink
Merge pull request #722 from ceedubs/streamingt-tostring
Browse files Browse the repository at this point in the history
Make StreamingT toString more like Streaming toString
  • Loading branch information
fthomas committed Dec 7, 2015
2 parents 492b030 + b6736ba commit b8be77b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 5 additions & 4 deletions core/src/main/scala/cats/data/StreamingT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,12 @@ sealed abstract class StreamingT[F[_], A] extends Product with Serializable { lh
* This method will not force evaluation of any lazy part of a
* stream. As a result, you will see at most one element (the first
* one).
*
* Use .toString(n) to see the first n elements of the stream.
*/
override def toString: String =
"StreamingT(...)"
override def toString: String = this match {
case Cons(a, _) => s"StreamingT($a, ...)"
case Wait(_) => "StreamingT(...)"
case Empty() => "StreamingT()"
}
}

object StreamingT extends StreamingTInstances {
Expand Down
8 changes: 8 additions & 0 deletions tests/src/test/scala/cats/tests/StreamingTTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ class StreamingTTests extends CatsSuite {
StreamingT[Id, Int](x1, x2, tail: _*) should === (fromList)
}
}

test("toString is wrapped in StreamingT()"){
forAll { (xs: StreamingT[Option, Int]) =>
val s = xs.toString
s.take(11) should === ("StreamingT(")
s.last should === (')')
}
}
}

class SpecificStreamingTTests extends CatsSuite {
Expand Down

0 comments on commit b8be77b

Please sign in to comment.