From 29b4f4c84034b99a6beee74aacb6d758290a1aac Mon Sep 17 00:00:00 2001 From: Chris Davenport Date: Thu, 10 May 2018 15:14:53 -0400 Subject: [PATCH] Initial Commit --- .gitignore | 7 ++ .scalafmt.conf | 25 +++++ .travis.yml | 19 ++++ README.md | 2 + build.sbt | 101 ++++++++++++++++++ project/build.properties | 1 + project/plugins.sbt | 8 ++ .../scalacheck/cats/implicits/implicits.scala | 5 + .../org/scalacheck/cats/instances/gen.scala | 46 ++++++++ version.sbt | 1 + 10 files changed, 215 insertions(+) create mode 100644 .gitignore create mode 100644 .scalafmt.conf create mode 100644 .travis.yml create mode 100644 README.md create mode 100644 build.sbt create mode 100644 project/build.properties create mode 100644 project/plugins.sbt create mode 100644 src/main/scala/org/scalacheck/cats/implicits/implicits.scala create mode 100644 src/main/scala/org/scalacheck/cats/instances/gen.scala create mode 100644 version.sbt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..646924c --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +target/ +.idea/ +# vim +*.sw? + +# Ignore [ce]tags files +tags diff --git a/.scalafmt.conf b/.scalafmt.conf new file mode 100644 index 0000000..3105820 --- /dev/null +++ b/.scalafmt.conf @@ -0,0 +1,25 @@ +# tune this file as appropriate to your style! see: https://olafurpg.github.io/scalafmt/#Configuration + +maxColumn = 100 + +continuationIndent.callSite = 2 + +newlines { + sometimesBeforeColonInMethodReturnType = false +} + +align { + arrowEnumeratorGenerator = false + ifWhileOpenParen = false + openParenCallSite = false + openParenDefnSite = false + + tokens = ["%", "%%"] +} + +docstrings = JavaDoc + +rewrite { + rules = [SortImports, RedundantBraces] + redundantBraces.maxLines = 1 +} diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..08332d5 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,19 @@ +sudo: false +language: scala + +scala: + - 2.12.6 + - 2.11.12 + +before_cache: + - find $HOME/.sbt -name "*.lock" -type f -delete + - find $HOME/.ivy2/cache -name "ivydata-*.properties" -type f -delete + +cache: + directories: + - $HOME/.ivy2/cache + - $HOME/.coursier/cache + - $HOME/.sbt + +jdk: + - oraclejdk8 diff --git a/README.md b/README.md new file mode 100644 index 0000000..2679291 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# cats-scalacheck + diff --git a/build.sbt b/build.sbt new file mode 100644 index 0000000..64c15b3 --- /dev/null +++ b/build.sbt @@ -0,0 +1,101 @@ +lazy val core = project.in(file(".")) + .settings(commonSettings) + .settings( + name := "cats-scalacheck" + ) + +val catsV = "1.1.0" +val scalacheckV = "1.14.0" + + +val specs2V = "4.2.0" +val disciplineV = "0.8" + + +lazy val contributors = Seq( + "ChristopherDavenport" -> "Christopher Davenport" +) + +lazy val commonSettings = Seq( + organization := "io.chrisdavenport", + + scalaVersion := "2.12.6", + crossScalaVersions := Seq(scalaVersion.value, "2.11.12"), + + addCompilerPlugin("org.spire-math" % "kind-projector" % "0.9.6" cross CrossVersion.binary), + + libraryDependencies ++= Seq( + "org.typelevel" %% "cats-core" % catsV, + "org.scalacheck" %% "scalacheck" % scalacheckV, + + "org.specs2" %% "specs2-core" % specs2V % Test, + "org.specs2" %% "specs2-scalacheck" % specs2V % Test, + "org.typelevel" %% "discipline" % disciplineV % Test + ) +) + +lazy val releaseSettings = { + import ReleaseTransformations._ + Seq( + releaseCrossBuild := true, + releaseProcess := Seq[ReleaseStep]( + checkSnapshotDependencies, + inquireVersions, + runClean, + runTest, + setReleaseVersion, + commitReleaseVersion, + tagRelease, + // For non cross-build projects, use releaseStepCommand("publishSigned") + releaseStepCommandAndRemaining("+publishSigned"), + setNextVersion, + commitNextVersion, + releaseStepCommand("sonatypeReleaseAll"), + pushChanges + ), + publishTo := { + val nexus = "https://oss.sonatype.org/" + if (isSnapshot.value) + Some("snapshots" at nexus + "content/repositories/snapshots") + else + Some("releases" at nexus + "service/local/staging/deploy/maven2") + }, + credentials ++= ( + for { + username <- Option(System.getenv().get("SONATYPE_USERNAME")) + password <- Option(System.getenv().get("SONATYPE_PASSWORD")) + } yield + Credentials( + "Sonatype Nexus Repository Manager", + "oss.sonatype.org", + username, + password + ) + ).toSeq, + publishArtifact in Test := false, + releasePublishArtifactsAction := PgpKeys.publishSigned.value, + scmInfo := Some( + ScmInfo( + url("https://github.com/ChristopherDavenport/cats-scalacheck"), + "git@github.com:ChristopherDavenport/cats-scalacheck.git" + ) + ), + homepage := Some(url("https://github.com/ChristopherDavenport/cats-scalacheck")), + licenses += ("MIT", url("http://opensource.org/licenses/MIT")), + publishMavenStyle := true, + pomIncludeRepository := { _ => + false + }, + pomExtra := { + + {for ((username, name) <- contributors) yield + + {username} + {name} + http://github.com/{username} + + } + + } + ) +} diff --git a/project/build.properties b/project/build.properties new file mode 100644 index 0000000..7c81737 --- /dev/null +++ b/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.1.5 diff --git a/project/plugins.sbt b/project/plugins.sbt new file mode 100644 index 0000000..655f0a8 --- /dev/null +++ b/project/plugins.sbt @@ -0,0 +1,8 @@ +addSbtPlugin("com.dwijnand" % "sbt-travisci" % "1.1.1") +addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.9.3") +addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.1") +addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.3") +addSbtPlugin("org.lyranthe.sbt" % "partial-unification" % "1.1.0") +addSbtPlugin("com.lucidchart" % "sbt-scalafmt" % "1.15") +addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.8") +addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.3") \ No newline at end of file diff --git a/src/main/scala/org/scalacheck/cats/implicits/implicits.scala b/src/main/scala/org/scalacheck/cats/implicits/implicits.scala new file mode 100644 index 0000000..007b502 --- /dev/null +++ b/src/main/scala/org/scalacheck/cats/implicits/implicits.scala @@ -0,0 +1,5 @@ +package org.scalacheck.cats + +import org.scalacheck.cats.instances.GenInstances + +package object implicits extends GenInstances diff --git a/src/main/scala/org/scalacheck/cats/instances/gen.scala b/src/main/scala/org/scalacheck/cats/instances/gen.scala new file mode 100644 index 0000000..f18adc0 --- /dev/null +++ b/src/main/scala/org/scalacheck/cats/instances/gen.scala @@ -0,0 +1,46 @@ +package org.scalacheck.cats.instances + +import cats._ +import cats.implicits._ +import org.scalacheck.Gen + +object GenInstances extends GenInstances + +trait GenInstances extends GenInstances1 + + sealed private[instances] trait GenInstances1 extends GenInstances0 { + implicit val genInstances : Monad[Gen] with SemigroupK[Gen] = new Monad[Gen] with Alternative[Gen] { + // Members declared in cats.Applicative + override def pure[A](x: A): Gen[A] = Gen.const(x) + + // Members declared in cats.FlatMap + override def flatMap[A, B](fa: Gen[A])(f: A => Gen[B]): Gen[B] = fa.flatMap(f) + override def tailRecM[A, B](a: A)(f: A => Gen[Either[A,B]]): Gen[B] = Gen.tailRecM(a)(f) + + override def combineK[A](x: Gen[A], y: Gen[A]): Gen[A] = Gen.gen{ (params, seed) => + val xGen = x.doApply(params, seed) + if (xGen.retrieve.isDefined) xGen + else y.doApply(params, seed) + } + + override def empty[A]: Gen[A] = Gen.fail + } + + implicit def genMonoid[A: Monoid]: Monoid[Gen[A]] = new Monoid[Gen[A]]{ + override def empty: Gen[A] = Gen.const(Monoid[A].empty) + override def combine(x: Gen[A], y: Gen[A]) = for { + xa <- x + ya <- y + } yield xa |+| ya + } + + } + + sealed private[instances] trait GenInstances0 { + implicit def genSemigroup[A: Semigroup]: Semigroup[Gen[A]] = new Semigroup[Gen[A]]{ + override def combine(x: Gen[A], y: Gen[A]) = for { + xa <- x + ya <- y + } yield xa |+| ya + } + } diff --git a/version.sbt b/version.sbt new file mode 100644 index 0000000..d63f66a --- /dev/null +++ b/version.sbt @@ -0,0 +1 @@ +version in ThisBuild := "0.0.1-SNAPSHOT" \ No newline at end of file