Skip to content

Commit

Permalink
SBT 1.x and Cats 1.0.0-RC1
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidGregory084 committed Nov 9, 2017
1 parent d86d3ee commit 7deb5ef
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 77 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: scala
scala:
- 2.10.6
- 2.11.11
- 2.12.3
- 2.12.4

jdk:
- oraclejdk8
Expand All @@ -13,11 +13,11 @@ env:
matrix:
# Add a job for 2.12 which publishes the site
include:
- scala: 2.12.3
- scala: 2.12.4
env: PUBLISH_SITE=true
# Remove the 2.12 job that doesn't publish the site
exclude:
- scala: 2.12.3
- scala: 2.12.4
env:

before_install:
Expand Down
34 changes: 20 additions & 14 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,24 @@ lazy val docs = project.in(file("docs"))
lazy val commonSettings = Seq(
organization := "io.github.davidgregory084",

organizationName := "David Gregory",

releaseCrossBuild := true,

libraryDependencies ++= Seq(
"org.typelevel" %% "cats-core" % "1.0.0-MF",
"org.typelevel" %% "cats-testkit" % "1.0.0-MF" % Test
"org.typelevel" %% "cats-core" % "1.0.0-RC1",
"org.typelevel" %% "cats-testkit" % "1.0.0-RC1" % Test
),

createHeaders.in(Compile) := {
createHeaders.in(Compile).triggeredBy(compile.in(Compile)).value
headerCreate.in(Compile) := {
headerCreate.in(Compile).triggeredBy(compile.in(Compile)).value
},

addCompilerPlugin("org.spire-math" % "kind-projector" % "0.9.3" cross CrossVersion.binary),
addCompilerPlugin("org.spire-math" % "kind-projector" % "0.9.4" cross CrossVersion.binary),

headers := {
import de.heikoseeberger.sbtheader.license._
Map("scala" -> Apache2_0("2017", "David Gregory and the Robots project contributors"))
},
headerLicense := Some(HeaderLicense.ALv2("2017", "David Gregory and the Robots project contributors")),

unmanagedSources.in(Compile, createHeaders) ++= (sourceDirectory.in(Compile).value / "boilerplate" ** "*.template").get,
unmanagedSources.in(Compile, headerCreate) ++= (sourceDirectory.in(Compile).value / "boilerplate" ** "*.template").get,

coursierVerbosity := {
val travisBuild = isTravisBuild.in(Global).value
Expand All @@ -105,7 +104,9 @@ lazy val publishSettings = Seq(

homepage := Some(url("https://github.com/DavidGregory084/robots")),

licenses := Seq("Apache 2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
startYear := Some(2017),

licenses += ("Apache 2.0", url("https://www.apache.org/licenses/LICENSE-2.0.txt")),

scmInfo := Some(ScmInfo(
url("https://github.com/DavidGregory084/robots"),
Expand Down Expand Up @@ -163,14 +164,19 @@ lazy val publishSettings = Seq(
publishArtifacts,
setNextVersion,
commitNextVersion,
ReleaseStep(action = Command.process("sonatypeReleaseAll", _), enableCrossBuild = true),
ReleaseStep(
action = state => state.copy(
remainingCommands = Exec("sonatypeReleaseAll", None) +: state.remainingCommands
),
enableCrossBuild = true
),
pushChanges
)
}
)

lazy val noPublishSettings = Seq(
publish := (),
publishLocal := (),
publish := {},
publishLocal := {},
publishArtifact := false
)
55 changes: 26 additions & 29 deletions core/src/main/scala/robots/PValidator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package robots

import cats.{ Applicative, ApplicativeError, Foldable, MonoidK, Semigroup, SemigroupK, Traverse }
import cats.arrow.{ Category, Choice }
import cats.functor.{ Contravariant, Profunctor }
import cats.arrow.{ Category, Choice, Profunctor }
import cats.Contravariant
import cats.data.NonEmptyList

final case class PValidator[F[_], E, A, B](val validate: A => F[E], f: A => B)(implicit FF: Traverse[F], M: MonoidK[F]) {
Expand Down Expand Up @@ -91,11 +91,16 @@ final case class PValidator[F[_], E, A, B](val validate: A => F[E], f: A => B)(i
TM.map(g(a))(c => (f(a), c))
}

def at[M[_], C](f: A => M[C], i: Int)(that: PValidator[F, E, Option[C], _])(implicit TM: Traverse[M]): PValidator[F, E, A, B] =
this and that.contramap(a => TM.toList(f(a)).lift(i))
def allIndexed[M[_], C](g: A => M[C])(that: PValidator[F, E, (C, Int), _])(implicit TM: Traverse[M]): PValidator[F, E, A, B] =
this and that.over[M].contramap { a =>
TM.zipWithIndex(g(a))
}

def at[M[_], C](f: A => M[C], i: Long)(that: PValidator[F, E, Option[C], _])(implicit TM: Traverse[M]): PValidator[F, E, A, B] =
this and that.contramap(a => TM.get(f(a))(i))

def first[M[_], C](f: A => M[C])(that: PValidator[F, E, Option[C], _])(implicit FM: Foldable[M]): PValidator[F, E, A, B] =
this and that.contramap(a => FM.toList(f(a)).headOption)
this and that.contramap(a => FM.get(f(a))(0))
}

object PValidator extends PValidatorInstances
Expand All @@ -105,8 +110,7 @@ private[robots] sealed abstract class PValidatorInstances {
implicit def robotsApplicativeForPValidator[F[_], E, A](
implicit
F0: Traverse[F],
M0: MonoidK[F]
): Applicative[PValidator[F, E, A, ?]] =
M0: MonoidK[F]): Applicative[PValidator[F, E, A, ?]] =
new PValidatorApplicative[F, E, A] {
def F: Traverse[F] = F0
def M: MonoidK[F] = M0
Expand All @@ -115,8 +119,7 @@ private[robots] sealed abstract class PValidatorInstances {
implicit def robotsChoiceForPValidator[F[_], E](
implicit
F0: Traverse[F],
M0: MonoidK[F]
): Choice[PValidator[F, E, ?, ?]] =
M0: MonoidK[F]): Choice[PValidator[F, E, ?, ?]] =
new PValidatorChoice[F, E] {
def F: Traverse[F] = F0
def M: MonoidK[F] = M0
Expand All @@ -125,8 +128,7 @@ private[robots] sealed abstract class PValidatorInstances {
implicit def robotsContravariantForPValidator[F[_], E, B](
implicit
F0: Traverse[F],
M0: MonoidK[F]
): Contravariant[PValidator[F, E, ?, B]] =
M0: MonoidK[F]): Contravariant[PValidator[F, E, ?, B]] =
new PValidatorContravariant[F, E, B] {
def F: Traverse[F] = F0
def M: MonoidK[F] = M0
Expand All @@ -135,8 +137,7 @@ private[robots] sealed abstract class PValidatorInstances {
implicit def robotsProfunctorForPValidator[F[_], E](
implicit
F0: Traverse[F],
M0: MonoidK[F]
): Profunctor[PValidator[F, E, ?, ?]] =
M0: MonoidK[F]): Profunctor[PValidator[F, E, ?, ?]] =
new PValidatorProfunctor[F, E] {
def F: Traverse[F] = F0
def M: MonoidK[F] = M0
Expand All @@ -145,8 +146,7 @@ private[robots] sealed abstract class PValidatorInstances {
implicit def robotsSemigroupForPValidator[F[_], E, A, B](
implicit
F0: Traverse[F],
M0: MonoidK[F]
): Semigroup[PValidator[F, E, A, B]] =
M0: MonoidK[F]): Semigroup[PValidator[F, E, A, B]] =
new PValidatorSemigroup[F, E, A, B] {
def F: Traverse[F] = F0
def M: MonoidK[F] = M0
Expand All @@ -155,16 +155,15 @@ private[robots] sealed abstract class PValidatorInstances {
implicit def robotsSemigroupKForPValidator[F[_], E, B](
implicit
F0: Traverse[F],
M0: MonoidK[F]
): SemigroupK[PValidator[F, E, ?, B]] =
M0: MonoidK[F]): SemigroupK[PValidator[F, E, ?, B]] =
new PValidatorSemigroupK[F, E, B] {
def F: Traverse[F] = F0
def M: MonoidK[F] = M0
}
}

private trait PValidatorApplicative[F[_], E, A]
extends Applicative[PValidator[F, E, A, ?]] {
extends Applicative[PValidator[F, E, A, ?]] {
implicit def F: Traverse[F]
implicit def M: MonoidK[F]

Expand All @@ -176,7 +175,7 @@ private trait PValidatorApplicative[F[_], E, A]
}

private trait PValidatorCategory[F[_], E]
extends Category[PValidator[F, E, ?, ?]] {
extends Category[PValidator[F, E, ?, ?]] {
implicit def F: Traverse[F]
implicit def M: MonoidK[F]

Expand All @@ -185,24 +184,22 @@ private trait PValidatorCategory[F[_], E]

def compose[A, B, C](
f: PValidator[F, E, B, C],
g: PValidator[F, E, A, B]
): PValidator[F, E, A, C] = g andThen f
g: PValidator[F, E, A, B]): PValidator[F, E, A, C] = g andThen f
}

private trait PValidatorChoice[F[_], E]
extends PValidatorCategory[F, E]
with Choice[PValidator[F, E, ?, ?]] {
extends PValidatorCategory[F, E]
with Choice[PValidator[F, E, ?, ?]] {
implicit def F: Traverse[F]
implicit def M: MonoidK[F]

def choice[A, B, C](
f: PValidator[F, E, A, C],
g: PValidator[F, E, B, C]
): PValidator[F, E, Either[A, B], C] = f or g
g: PValidator[F, E, B, C]): PValidator[F, E, Either[A, B], C] = f or g
}

private trait PValidatorContravariant[F[_], E, B]
extends Contravariant[PValidator[F, E, ?, B]] {
extends Contravariant[PValidator[F, E, ?, B]] {
implicit def F: Traverse[F]
implicit def M: MonoidK[F]

Expand All @@ -211,7 +208,7 @@ private trait PValidatorContravariant[F[_], E, B]
}

private trait PValidatorProfunctor[F[_], E]
extends Profunctor[PValidator[F, E, ?, ?]] {
extends Profunctor[PValidator[F, E, ?, ?]] {
implicit def F: Traverse[F]
implicit def M: MonoidK[F]

Expand All @@ -226,7 +223,7 @@ private trait PValidatorProfunctor[F[_], E]
}

private trait PValidatorSemigroup[F[_], E, A, B]
extends Semigroup[PValidator[F, E, A, B]] {
extends Semigroup[PValidator[F, E, A, B]] {
implicit def F: Traverse[F]
implicit def M: MonoidK[F]

Expand All @@ -235,7 +232,7 @@ private trait PValidatorSemigroup[F[_], E, A, B]
}

private trait PValidatorSemigroupK[F[_], E, B]
extends SemigroupK[PValidator[F, E, ?, B]] {
extends SemigroupK[PValidator[F, E, ?, B]] {
implicit def F: Traverse[F]
implicit def M: MonoidK[F]

Expand Down
24 changes: 9 additions & 15 deletions core/src/test/scala/robots/ValidatorTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package robots

import cats.{ ApplicativeError, Eq, MonoidK, Traverse }
import cats.data.{ NonEmptyList, Validated }
import cats.kernel.laws._
import cats.kernel.laws.discipline._
import cats.laws.discipline._
import cats.laws.discipline.eq._
import cats.tests.CatsSuite
Expand All @@ -23,13 +23,13 @@ class ValidatorTests extends CatsSuite {

checkAll("PValidator[List, Int, Int, Int]", ApplicativeTests[PValidator[List, Int, Int, ?]].applicative[Int, Int, Int])

checkAll("PValidator[List, Int, Int, Int]", CartesianTests[PValidator[List, Int, Int, ?]].cartesian[Int, Int, Int])
checkAll("PValidator[List, Int, Int, Int]", SemigroupalTests[PValidator[List, Int, Int, ?]].semigroupal[Int, Int, Int])

checkAll("PValidator[List, Int, Int, Int]", ChoiceTests[PValidator[List, Int, ?, ?]].choice[Int, Int, Int, Int])

checkAll("PValidator[List, Int, Int, Int]", ContravariantTests[PValidator[List, Int, ?, Int]].contravariant[Int, Int, Int])

checkAll("PValidator[List, Int, Int, Int]", GroupLaws[PValidator[List, Int, Int, Int]].semigroup)
checkAll("PValidator[List, Int, Int, Int]", SemigroupTests[PValidator[List, Int, Int, Int]].semigroup)

checkAll("PValidator[List, Int, Int, Int]", ProfunctorTests[PValidator[List, Int, ?, ?]].profunctor[Int, Int, Int, Int, Int, Int])

Expand Down Expand Up @@ -208,8 +208,7 @@ class ValidatorTests extends CatsSuite {
documentValidator.run[Validated](valid) should ===(Validated.Valid(valid))

documentValidator.run[Validated](invalid) should ===(Validated.Invalid(
NonEmptyList.of("The number of lines in this document exceeds the maximum of 1")
))
NonEmptyList.of("The number of lines in this document exceeds the maximum of 1")))
}

test("Validate using all") {
Expand All @@ -231,8 +230,7 @@ class ValidatorTests extends CatsSuite {
documentValidator.run[Validated](valid) should ===(Validated.Valid(valid))

documentValidator.run[Validated](invalid) should ===(Validated.Invalid(
NonEmptyList.of("Empty lines are not permitted")
))
NonEmptyList.of("Empty lines are not permitted")))
}

test("Validate using all2") {
Expand All @@ -255,8 +253,7 @@ class ValidatorTests extends CatsSuite {
documentValidator.run[Validated](valid) should ===(Validated.Valid(valid))

documentValidator.run[Validated](invalid) should ===(Validated.Invalid(
NonEmptyList.of("The line exceeds the maximum width of 4 columns")
))
NonEmptyList.of("The line exceeds the maximum width of 4 columns")))
}

test("Validate using at") {
Expand All @@ -278,8 +275,7 @@ class ValidatorTests extends CatsSuite {
documentValidator.run[Validated](valid) should ===(Validated.Valid(valid))

documentValidator.run[Validated](invalid) should ===(Validated.Invalid(
NonEmptyList.of("A document should have at least two lines")
))
NonEmptyList.of("A document should have at least two lines")))
}

test("Validate using first") {
Expand All @@ -301,8 +297,7 @@ class ValidatorTests extends CatsSuite {
documentValidator.run[Validated](valid) should ===(Validated.Valid(valid))

documentValidator.run[Validated](invalid) should ===(Validated.Invalid(
NonEmptyList.of("A document should start with 'Hello'")
))
NonEmptyList.of("A document should start with 'Hello'")))
}

test("Produce a validator that always fails using fail") {
Expand All @@ -324,8 +319,7 @@ class ValidatorTests extends CatsSuite {
val expected = Validated.Invalid(NonEmptyList.of(
"0 WAS NOT GREATER THAN 0",
"-4 WAS NOT GREATER THAN 0",
"-20 WAS NOT GREATER THAN 0"
))
"-20 WAS NOT GREATER THAN 0"))

results should ===(expected)
}
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.15
sbt.version=1.0.3
26 changes: 12 additions & 14 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.5")
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.6")

addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.1")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0")

addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "1.1")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.0")

addSbtPlugin("io.spray" % "sbt-boilerplate" % "0.6.0")
addSbtPlugin("org.tpolecat" % "tut-plugin" % "0.6.2")

addSbtPlugin("org.tpolecat" % "tut-plugin" % "0.5.2")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1")

addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.0")
addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.0")

addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.6.0")
addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-RC11")

addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-RC6")
addSbtPlugin("com.dwijnand" % "sbt-travisci" % "1.1.1")

addSbtPlugin("com.dwijnand" % "sbt-travisci" % "1.1.0")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "3.0.2")

addSbtPlugin("de.heikoseeberger" % "sbt-header" % "1.8.0")
addSbtPlugin("com.47deg" % "sbt-microsites" % "0.7.6")

addSbtPlugin("com.47deg" % "sbt-microsites" % "0.6.1")
addSbtPlugin("com.eed3si9n" % "sbt-unidoc" % "0.4.1")

addSbtPlugin("com.eed3si9n" % "sbt-unidoc" % "0.4.0")

addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.2")
addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.3")
2 changes: 1 addition & 1 deletion project/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-RC6")
addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-RC11")

0 comments on commit 7deb5ef

Please sign in to comment.