From 24e3a4137fd7b83034ca8a4bfac39a42ab9514e2 Mon Sep 17 00:00:00 2001 From: Kailuo Wang Date: Thu, 6 Apr 2017 20:42:29 -0400 Subject: [PATCH 1/3] added instances of BitSet to allInstances --- core/src/main/scala/cats/instances/all.scala | 1 + .../main/scala/cats/instances/bitSet.scala | 13 ++++++++++++ .../main/scala/cats/instances/package.scala | 1 + .../test/scala/cats/tests/BitSetTests.scala | 21 +++++++++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 core/src/main/scala/cats/instances/bitSet.scala create mode 100644 tests/src/test/scala/cats/tests/BitSetTests.scala diff --git a/core/src/main/scala/cats/instances/all.scala b/core/src/main/scala/cats/instances/all.scala index 18068be967..586d5f287d 100644 --- a/core/src/main/scala/cats/instances/all.scala +++ b/core/src/main/scala/cats/instances/all.scala @@ -14,6 +14,7 @@ trait AllInstances with MapInstances with BigIntInstances with BigDecimalInstances + with BitSetInstances with FutureInstances with TryInstances with TupleInstances diff --git a/core/src/main/scala/cats/instances/bitSet.scala b/core/src/main/scala/cats/instances/bitSet.scala new file mode 100644 index 0000000000..51d48e63b1 --- /dev/null +++ b/core/src/main/scala/cats/instances/bitSet.scala @@ -0,0 +1,13 @@ +package cats.instances + +import scala.collection.immutable.BitSet +import int.catsStdShowForInt +import cats.syntax.show._ +import cats.Show + +trait BitSetInstances extends cats.kernel.instances.BitSetInstances { + implicit def catsStdShowForBitSet: Show[BitSet] = new Show[BitSet] { + def show(fa: BitSet): String = + fa.toIterator.map(_.show).mkString("BitSet(", ", ", ")") + } +} diff --git a/core/src/main/scala/cats/instances/package.scala b/core/src/main/scala/cats/instances/package.scala index 8f1a10cad3..d08087f022 100644 --- a/core/src/main/scala/cats/instances/package.scala +++ b/core/src/main/scala/cats/instances/package.scala @@ -9,6 +9,7 @@ package object instances { object list extends ListInstances object option extends OptionInstances object set extends SetInstances + object bitSet extends BitSetInstances object stream extends StreamInstances object vector extends VectorInstances object map extends MapInstances diff --git a/tests/src/test/scala/cats/tests/BitSetTests.scala b/tests/src/test/scala/cats/tests/BitSetTests.scala new file mode 100644 index 0000000000..ac79dc764c --- /dev/null +++ b/tests/src/test/scala/cats/tests/BitSetTests.scala @@ -0,0 +1,21 @@ +package cats.tests + +import org.scalacheck.Arbitrary +import org.scalacheck.Arbitrary.arbitrary + +import scala.collection.immutable.BitSet + +class BitSetTests extends CatsSuite { + implicit val arbitraryBitSet: Arbitrary[BitSet] = + Arbitrary(arbitrary[List[Short]].map(ns => BitSet(ns.map(_ & 0xffff): _*))) + + test("show BitSet"){ + BitSet(1, 1, 2, 3).show should === ("BitSet(1, 2, 3)") + BitSet.empty.show should === ("BitSet()") + + forAll { fs: BitSet => + fs.show should === (fs.toString) + } + } + +} From 6e3ed2e26647a76109251f8dfb7595da0a1dc4a8 Mon Sep 17 00:00:00 2001 From: Kailuo Wang Date: Thu, 6 Apr 2017 22:29:08 -0400 Subject: [PATCH 2/3] unnecessary show implementation --- core/src/main/scala/cats/instances/bitSet.scala | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/core/src/main/scala/cats/instances/bitSet.scala b/core/src/main/scala/cats/instances/bitSet.scala index 51d48e63b1..11a64846eb 100644 --- a/core/src/main/scala/cats/instances/bitSet.scala +++ b/core/src/main/scala/cats/instances/bitSet.scala @@ -6,8 +6,5 @@ import cats.syntax.show._ import cats.Show trait BitSetInstances extends cats.kernel.instances.BitSetInstances { - implicit def catsStdShowForBitSet: Show[BitSet] = new Show[BitSet] { - def show(fa: BitSet): String = - fa.toIterator.map(_.show).mkString("BitSet(", ", ", ")") - } + implicit def catsStdShowForBitSet: Show[BitSet] = Show.fromToString[BitSet] } From 0ea5608d72f33e5c8d40b19866d6b9537fda5a01 Mon Sep 17 00:00:00 2001 From: Kailuo Wang Date: Fri, 7 Apr 2017 08:02:22 -0400 Subject: [PATCH 3/3] removed unused imports --- core/src/main/scala/cats/instances/bitSet.scala | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/src/main/scala/cats/instances/bitSet.scala b/core/src/main/scala/cats/instances/bitSet.scala index 11a64846eb..dc14fe8276 100644 --- a/core/src/main/scala/cats/instances/bitSet.scala +++ b/core/src/main/scala/cats/instances/bitSet.scala @@ -1,8 +1,6 @@ package cats.instances import scala.collection.immutable.BitSet -import int.catsStdShowForInt -import cats.syntax.show._ import cats.Show trait BitSetInstances extends cats.kernel.instances.BitSetInstances {