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

replace Stream in ExhaustiveCheck with List #2896

Merged
merged 2 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
32 changes: 17 additions & 15 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,23 @@ crossScalaVersionsFromTravis in Global := {
}
}

def scalaVersionSpecificFolders(srcName: String, srcBaseDir: java.io.File, scalaVersion: String) = {
def extraDirs(suffix: String) =
CrossType.Pure.sharedSrcDir(srcBaseDir, "main").toList.map(f => file(f.getPath + suffix))
CrossVersion.partialVersion(scalaVersion) match {
case Some((2, y)) if y <= 12 =>
extraDirs("-2.12-")
case Some((2, y)) if y >= 13 =>
extraDirs("-2.13+")
case _ => Nil
}
}

lazy val commonSettings = Seq(
crossScalaVersions := (crossScalaVersionsFromTravis in Global).value,
scalacOptions ++= commonScalacOptions(scalaVersion.value),
Compile / unmanagedSourceDirectories ++= {
val bd = baseDirectory.value
def extraDirs(suffix: String) =
CrossType.Pure.sharedSrcDir(bd, "main").toList.map(f => file(f.getPath + suffix))
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, y)) if y <= 12 =>
extraDirs("-2.12-")
case Some((2, y)) if y >= 13 =>
extraDirs("-2.13+")
case _ => Nil
}
},
Compile / unmanagedSourceDirectories ++= scalaVersionSpecificFolders("main", baseDirectory.value, scalaVersion.value),
Test / unmanagedSourceDirectories ++= scalaVersionSpecificFolders("test", baseDirectory.value, scalaVersion.value),
resolvers ++= Seq(Resolver.sonatypeRepo("releases"), Resolver.sonatypeRepo("snapshots")),
parallelExecution in Test := false,
scalacOptions in (Compile, doc) := (scalacOptions in (Compile, doc)).value.filter(_ != "-Xfatal-warnings"),
Expand Down Expand Up @@ -801,13 +803,13 @@ def commonScalacOptions(scalaVersion: String) =
"-unchecked",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
"-Ywarn-value-discard",
"-Xfuture"
"-Ywarn-value-discard"
) ++ (if (priorTo2_13(scalaVersion))
Seq(
"-Yno-adapted-args",
"-Xfatal-warnings", // TODO: add the following two back to 2.13
"-deprecation"
"-deprecation",
"-Xfuture"
)
else
Seq(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cats
package instances
package cats.instances

package object symbol extends SymbolInstances
import cats.Show

trait SymbolInstances extends cats.kernel.instances.SymbolInstances {
implicit val catsStdShowForSymbol: Show[Symbol] =
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/scala/cats/instances/symbol/package.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package cats
package instances

package object symbol extends SymbolInstances
12 changes: 6 additions & 6 deletions laws/src/main/scala/cats/laws/discipline/ExhaustiveCheck.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ package discipline
* domain of values as opposed to generating a random sampling of values.
*/
trait ExhaustiveCheck[A] extends Serializable { self =>
def allValues: Stream[A]
def allValues: List[A]
}

object ExhaustiveCheck {
def apply[A](implicit A: ExhaustiveCheck[A]): ExhaustiveCheck[A] = A

def instance[A](values: Stream[A]): ExhaustiveCheck[A] = new ExhaustiveCheck[A] {
val allValues: Stream[A] = values
def instance[A](values: List[A]): ExhaustiveCheck[A] = new ExhaustiveCheck[A] {
val allValues: List[A] = values
}

implicit val catsLawsExhaustiveCheckForBoolean: ExhaustiveCheck[Boolean] =
instance(Stream(false, true))
instance(List(false, true))

implicit val catsLawsExhaustiveCheckForSetBoolean: ExhaustiveCheck[Set[Boolean]] =
forSet[Boolean]
Expand Down Expand Up @@ -50,13 +50,13 @@ object ExhaustiveCheck {
instance(A.allValues.map(Left(_)) ++ B.allValues.map(Right(_)))

implicit def catsLawsExhaustiveCheckForOption[A](implicit A: ExhaustiveCheck[A]): ExhaustiveCheck[Option[A]] =
instance(Stream.cons(None, A.allValues.map(Some(_))))
instance(None :: A.allValues.map(Some(_)))

/**
* Creates an `ExhaustiveCheck[Set[A]]` given an `ExhaustiveCheck[A]` by computing the powerset of
* values. Note that if there are `n` elements in the domain of `A` there will be `2^n` elements
* in the domain of `Set[A]`, so use this only on small domains.
*/
def forSet[A](implicit A: ExhaustiveCheck[A]): ExhaustiveCheck[Set[A]] =
instance(A.allValues.toSet.subsets.toStream)
instance(A.allValues.toSet.subsets.toList)
}
4 changes: 2 additions & 2 deletions laws/src/main/scala/cats/laws/discipline/MiniInt.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ object MiniInt {
new MiniInt(i << intShift >>> intShift)
} else throw new IllegalArgumentException(s"Expected value between $minIntValue and $maxIntValue but got $i")

val allValues: Stream[MiniInt] = (minIntValue to maxIntValue).map(unsafeFromInt).toStream
val allValues: List[MiniInt] = (minIntValue to maxIntValue).map(unsafeFromInt).toList

implicit val catsLawsEqInstancesForMiniInt: Order[MiniInt] with Hash[MiniInt] = new Order[MiniInt]
with Hash[MiniInt] {
Expand All @@ -58,7 +58,7 @@ object MiniInt {
def compare(x: MiniInt, y: MiniInt): Int = Order[Int].compare(x.toInt, y.toInt)
}

implicit val catsLawsExhuastiveCheckForMiniInt: ExhaustiveCheck[MiniInt] =
implicit val catsLawsExhaustiveCheckForMiniInt: ExhaustiveCheck[MiniInt] =
ExhaustiveCheck.instance(allValues)

val miniIntAddition: CommutativeGroup[MiniInt] = new CommutativeGroup[MiniInt] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ object BinCodecInvariantMonoidalSuite {
implicit val exhaustiveCheckForMiniListBoolean: ExhaustiveCheck[MiniList[Boolean]] =
ExhaustiveCheck.instance(
for {
length <- (0 to maxLength).toStream
boolList <- List(false, true).replicateA(length).toStream
length <- (0 to maxLength).toList
boolList <- List(false, true).replicateA(length)
} yield MiniList.unsafe(boolList)
)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/src/test/scala/cats/tests/NonEmptySetSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import cats.laws.discipline._
import cats.laws.discipline.arbitrary._
import cats.data.NonEmptySet
import cats.kernel.Semilattice
import cats.kernel.laws.discipline.{EqTests, OrderTests, PartialOrderTests, SemilatticeTests}
import cats.kernel.laws.discipline.{EqTests, OrderTests, SemilatticeTests}

import scala.collection.immutable.SortedSet

Expand Down