Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added instances of BitSet to allInstances #1592

Merged
merged 3 commits into from
Apr 8, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/src/main/scala/cats/instances/all.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ trait AllInstances
with MapInstances
with BigIntInstances
with BigDecimalInstances
with BitSetInstances
with FutureInstances
with TryInstances
with TupleInstances
Expand Down
13 changes: 13 additions & 0 deletions core/src/main/scala/cats/instances/bitSet.scala
Original file line number Diff line number Diff line change
@@ -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(", ", ", ")")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would we use show here vs fa.toString? There is nothing generic about BitSet and the current implementation is just going to be the same as toString no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duh, I wasn't thinking when I mechanically copied from set instances.

}
}
1 change: 1 addition & 0 deletions core/src/main/scala/cats/instances/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions tests/src/test/scala/cats/tests/BitSetTests.scala
Original file line number Diff line number Diff line change
@@ -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)
}
}

}