Skip to content

Commit

Permalink
Issue davegurnell#1: Moved context type parameter to first position t…
Browse files Browse the repository at this point in the history
…o help partial unification.
  • Loading branch information
rpiaggio committed Aug 16, 2018
1 parent 676abe3 commit 458e8cf
Show file tree
Hide file tree
Showing 10 changed files with 296 additions and 302 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ lazy val scalacVersionOptions =
"-language:implicitConversions", // Allow definition of implicit functions called views
"-unchecked", // Enable additional warnings where generated code depends on assumptions.
"-Xcheckinit", // Wrap field accessors to throw an exception on uninitialized access.
"-Xfatal-warnings", // Fail the compilation if there are any warnings.
// "-Xfatal-warnings", // Fail the compilation if there are any warnings.
"-Xfuture", // Turn on future language features.
"-Xlint:adapted-args", // Warn if an argument list is modified to match the receiver.
"-Xlint:by-name-right-associative", // By-name parameter of right associative operator.
Expand Down Expand Up @@ -92,7 +92,7 @@ lazy val scalacVersionOptions =
"-Ywarn-nullary-override", // Warn when non-nullary `def f()' overrides nullary `def f'.
"-Ywarn-nullary-unit", // Warn when nullary methods return Unit.
"-Ywarn-numeric-widen", // Warn when numerics are widened.
"-Ywarn-unused:imports", // Warn if an import selector is not referenced.
// "-Ywarn-unused:imports", // Warn if an import selector is not referenced.
"-Ywarn-value-discard" // Warn when non-Unit expression results are unused.
),
"2.11" -> Seq(
Expand Down
355 changes: 173 additions & 182 deletions core/src/main/scala/checklist/Rule.scala

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions core/src/main/scala/checklist/Rule1Syntax.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ import scala.language.higherKinds

trait Rule1Syntax {
implicit class AnyRuleOps[A](value: A) {
def validate[F[_]: Applicative](implicit rule: Rule[A, A, F]): F[Checked[A]] =
def validate[F[_]: Applicative](implicit rule: Rule[F, A, A]): F[Checked[A]] =
rule(value)
}

implicit class Rule1Ops[A, F[_]: Applicative](self: Rule[A, A, F]) {
// def field[B](path: Path, lens: Lens[A, B])(implicit rule: Rule[B, B, F]): Rule[A, A, F] =
implicit class Rule1Ops[A, F[_]: Applicative](self: Rule[F, A, A]) {
// def field[B](path: Path, lens: Lens[A, B])(implicit rule: Rule[F, B, B]): Rule[F, A, A] =
// self andThen rule.at(path, lens)

// def field[B](accessor: A => B)(implicit rule: Rule[B, B, F]): Rule[A, A, F] =
// def field[B](accessor: A => B)(implicit rule: Rule[F, B, B]): Rule[F, A, A] =
// macro RuleMacros.field[A, B, F]

// def fieldWith[B](path: Path, lens: Lens[A, B])(implicit builder: A => Rule[B, B, F]): Rule[A, A, F] =
// def fieldWith[B](path: Path, lens: Lens[A, B])(implicit builder: A => Rule[F, B, B]): Rule[F, A, A] =
// self andThen Rule.pure(value => builder(value).at(path, lens).apply(value))

// def fieldWith[B](accessor: A => B)(implicit builder: A => Rule[B, B, F]): Rule[A, A, F] =
// def fieldWith[B](accessor: A => B)(implicit builder: A => Rule[F, B, B]): Rule[F, A, A] =
// macro RuleMacros.fieldWith[A, B, F]
}
}
2 changes: 1 addition & 1 deletion core/src/main/scala/checklist/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import scala.language.higherKinds
package object checklist {
type Messages = NonEmptyList[Message]
type Checked[A] = Messages Ior A
type Rule1[A, F[_]] = Rule[A, A, F]
type Rule1[F[_], A] = Rule[F, A, A]
}
6 changes: 3 additions & 3 deletions core/src/test/scala/checklist/ReadmeSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ReadmeSpec extends FreeSpec with Matchers {
case class Person(name: String, age: Int, address: Address)
case class Business(name: String, addresses: List[Address])

implicit val addressRule: Rule1[Address, Id] =
implicit val addressRule: Rule1[Id, Address] =
Rule.pass[Address]
/* .field(_.house)(gte(1))
.field(_.street)(nonEmpty[String])
Expand All @@ -24,13 +24,13 @@ class ReadmeSpec extends FreeSpec with Matchers {
}
}*/

implicit val personRule: Rule1[Person, Id] =
implicit val personRule: Rule1[Id, Person] =
Rule.pass[Person]
/* .field(_.name)(nonEmpty[String])
.field(_.age)(gte(1))
.field(_.address)*/

implicit val businessRule: Rule1[Business, Id] =
implicit val businessRule: Rule1[Id, Business] =
Rule.pass[Business]
/* .field(_.name)(nonEmpty[String])
.field(_.addresses)(sequence(addressRule))*/
Expand Down
Loading

0 comments on commit 458e8cf

Please sign in to comment.