From 8566afd663906b7716eccdcb09ce10e09529f177 Mon Sep 17 00:00:00 2001 From: Mike Curry Date: Sun, 3 Jan 2016 15:58:02 +0000 Subject: [PATCH] Adds Show[Vector] --- core/src/main/scala/cats/std/vector.scala | 6 ++++++ tests/src/test/scala/cats/tests/VectorTests.scala | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/core/src/main/scala/cats/std/vector.scala b/core/src/main/scala/cats/std/vector.scala index 9f88565c01..88d9797ceb 100644 --- a/core/src/main/scala/cats/std/vector.scala +++ b/core/src/main/scala/cats/std/vector.scala @@ -2,6 +2,7 @@ package cats package std import cats.data.Streaming +import cats.syntax.show._ trait VectorInstances { implicit val vectorInstance: Traverse[Vector] with MonadCombine[Vector] = @@ -43,6 +44,11 @@ trait VectorInstances { Streaming.fromVector(fa) } + implicit def vectorShow[A:Show]: Show[Vector[A]] = + new Show[Vector[A]] { + def show(fa: Vector[A]): String = fa.map(_.show).mkString("Vector(", ", ", ")") + } + // TODO: eventually use algebra's instances (which will deal with // implicit priority between Eq/PartialOrder/Order). diff --git a/tests/src/test/scala/cats/tests/VectorTests.scala b/tests/src/test/scala/cats/tests/VectorTests.scala index 3815b12369..423e101a15 100644 --- a/tests/src/test/scala/cats/tests/VectorTests.scala +++ b/tests/src/test/scala/cats/tests/VectorTests.scala @@ -13,4 +13,15 @@ class VectorTests extends CatsSuite { checkAll("Vector[Int] with Option", TraverseTests[Vector].traverse[Int, Int, Int, List[Int], Option, Option]) checkAll("Traverse[Vector]", SerializableTests.serializable(Traverse[Vector])) + + test("show") { + Vector(1, 2, 3).show should === ("Vector(1, 2, 3)") + + Vector.empty[Int].show should === ("Vector()") + + forAll { vec: Vector[String] => + vec.show should === (vec.toString) + } + } + }