-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix many cats-kernel instances. #1324
Changes from all commits
706effc
aeee001
e2e0996
cffe60f
db2eab3
2d3b474
24e4de2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package cats | ||
package instances | ||
|
||
trait BigDecimalInstances { | ||
trait BigDecimalInstances extends cats.kernel.instances.BigDecimalInstances { | ||
implicit val catsStdShowForBigDecimal: Show[BigDecimal] = | ||
Show.fromToString[BigDecimal] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,11 @@ import scala.annotation.tailrec | |
trait MapInstances extends cats.kernel.instances.MapInstances { | ||
|
||
implicit def catsStdShowForMap[A, B](implicit showA: Show[A], showB: Show[B]): Show[Map[A, B]] = | ||
Show.show[Map[A, B]] { m => | ||
val body = m.map { case (a, b) => | ||
s"${showA.show(a)} -> ${showB.show(b)})" | ||
}.mkString(",") | ||
s"Map($body)" | ||
new Show[Map[A, B]] { | ||
def show(m: Map[A, B]): String = | ||
m.iterator | ||
.map { case (a, b) => showA.show(a) + " -> " + showB.show(b) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought the compiler would rewrite it to us a string builder, but maybe that's only Java? I can rewrite this using interpolation (it just ends up looking uglier IMO). |
||
.mkString("Map(", ", ", ")") | ||
} | ||
|
||
// scalastyle:off method.length | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package cats.kernel | ||
package instances | ||
|
||
import scala.collection.immutable.BitSet | ||
|
||
package object bitSet extends BitSetInstances | ||
|
||
trait BitSetInstances { | ||
implicit val catsKernelStdPartialOrderForBitSet: PartialOrder[BitSet] = | ||
new BitSetPartialOrder | ||
|
||
implicit val catsKernelStdSemilatticeForBitSet: BoundedSemilattice[BitSet] = | ||
new BitSetSemilattice | ||
} | ||
|
||
class BitSetPartialOrder extends PartialOrder[BitSet] { | ||
def partialCompare(x: BitSet, y: BitSet): Double = | ||
if (x eq y) 0.0 | ||
else if (x.size < y.size) if (x.subsetOf(y)) -1.0 else Double.NaN | ||
else if (y.size < x.size) if (y.subsetOf(x)) 1.0 else Double.NaN | ||
else if (x == y) 0.0 | ||
else Double.NaN | ||
|
||
override def eqv(x: BitSet, y: BitSet): Boolean = | ||
x == y | ||
} | ||
|
||
class BitSetSemilattice extends BoundedSemilattice[BitSet] { | ||
def empty: BitSet = BitSet.empty | ||
def combine(x: BitSet, y: BitSet): BitSet = x | y | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch