-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit does a bunch of things: 1. Move relevant either/function instnaces into kernel 2. Add missing Eq/PartialOrder instances for Either 3. Add many missing instances for Function0/Function1 4. Add instances for BitSet 5. Remove code duplication between collection monoids 6. Improve test coverage of function instances 7. Add some missing package objects in kernel 8. A few stylistic changes This is a relatively large commit but I think almost all of this is stuff we'd like to get done before we freeze cats-kernel.
- Loading branch information
1 parent
06539fa
commit 706effc
Showing
19 changed files
with
486 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package cats.kernel | ||
package instances | ||
|
||
package object either extends EitherInstances | ||
|
||
trait EitherInstances extends EitherInstances0 { | ||
|
||
implicit def catsStdOrderForEither[A, B](implicit A: Order[A], B: Order[B]): Order[Either[A, B]] = | ||
new Order[Either[A, B]] { | ||
def compare(x: Either[A, B], y: Either[A, B]): Int = | ||
x match { | ||
case Left(xx) => y match { | ||
case Left(yy) => A.compare(xx, yy) | ||
case Right(_) => -1 | ||
} | ||
case Right(xx) => y match { | ||
case Left(_) => 1 | ||
case Right(yy) => B.compare(xx, yy) | ||
} | ||
} | ||
} | ||
|
||
implicit def catsDataMonoidForEither[A, B](implicit B: Monoid[B]): Monoid[Either[A, B]] = | ||
new Monoid[Either[A, B]] { | ||
def empty: Either[A, B] = | ||
Right(B.empty) | ||
def combine(x: Either[A, B], y: Either[A, B]): Either[A, B] = | ||
x match { | ||
case left @ Left(_) => left | ||
case Right(xx) => y match { | ||
case left @ Left(_) => left | ||
case Right(yy) => Right(B.combine(xx, yy)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
trait EitherInstances0 extends EitherInstances1 { | ||
|
||
implicit def catsStdPartialOrderForEither[A, B](implicit A: PartialOrder[A], B: PartialOrder[B]): PartialOrder[Either[A, B]] = | ||
new PartialOrder[Either[A, B]] { | ||
def partialCompare(x: Either[A, B], y: Either[A, B]): Double = | ||
x match { | ||
case Left(xx) => y match { | ||
case Left(yy) => A.partialCompare(xx, yy) | ||
case Right(_) => -1.0 | ||
} | ||
case Right(xx) => y match { | ||
case Left(_) => 1.0 | ||
case Right(yy) => B.partialCompare(xx, yy) | ||
} | ||
} | ||
} | ||
} | ||
|
||
trait EitherInstances1 { | ||
implicit def catsStdEqForEither[A, B](implicit A: Eq[A], B: Eq[B]): Eq[Either[A, B]] = | ||
new Eq[Either[A, B]] { | ||
def eqv(x: Either[A, B], y: Either[A, B]): Boolean = | ||
x match { | ||
case Left(xx) => y match { | ||
case Left(yy) => A.eqv(xx, yy) | ||
case Right(_) => false | ||
} | ||
case Right(xx) => y match { | ||
case Left(_) => false | ||
case Right(yy) => B.eqv(xx, yy) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.