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

WIP: Selective #3709

Draft
wants to merge 47 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
444e3bd
Introduce Selective
rossabaker Dec 9, 2020
da7f756
Split into Select and Selective
rossabaker Dec 9, 2020
d220349
Selective[Validated[E, *]]
rossabaker Dec 9, 2020
4c7f87e
SelectiveError
rossabaker Dec 9, 2020
14d3e42
FlatMap extends Select
rossabaker Dec 9, 2020
f554862
Merge branch 'master' into selective
rossabaker Dec 9, 2020
b7112ac
Required parens on lambda
rossabaker Dec 9, 2020
b8dc63b
Default select from Apply until Monad
rossabaker Dec 9, 2020
7fd409b
Start writing SelectiveLaws
rossabaker Dec 9, 2020
254bf7f
Look at me, not compiling before I push
rossabaker Dec 9, 2020
ed71f06
Never mind on Select
rossabaker Dec 9, 2020
7767906
branch, ifS, whenS
rossabaker Dec 9, 2020
466354b
select is an abstract member of Selective
rossabaker Dec 10, 2020
f31020a
Law for monad select rigidity
rossabaker Dec 10, 2020
4a2b0be
scalafmt
rossabaker Dec 10, 2020
955a03b
Use our new syntax
rossabaker Dec 10, 2020
e35a097
Test default operations
rossabaker Dec 10, 2020
df699d1
Derive missing implicits for selective laws
rossabaker Dec 14, 2020
a50da48
Remove SelectiveError for now
rossabaker Dec 14, 2020
387ab75
Selective distributivity and associativity
rossabaker Dec 14, 2020
cb51502
Clean up syntax
rossabaker Dec 14, 2020
06abe62
apS and RigidSelective laws
rossabaker Dec 16, 2020
9b001dd
Remove inner scope in branch
rossabaker Dec 16, 2020
19b67b4
Move EitherUtil to root package for use in typeclasses
rossabaker Dec 16, 2020
662cf5a
Use cached either units in ifS
rossabaker Dec 16, 2020
936847f
Fix loop in laws inheritance
rossabaker Dec 16, 2020
3372948
Remove unnecessary private[cats] in EitherUtil
rossabaker Dec 16, 2020
a866a20
Apply.selectA
rossabaker Dec 16, 2020
260a219
select's function is lazy; skip on right law for rigids
rossabaker Dec 16, 2020
a0f8709
Skip effects in branch and ifS in rigid selectives
rossabaker Dec 16, 2020
37594b9
Skip effect of whenS when false in rigid selectives
rossabaker Dec 16, 2020
b56130d
Replace apS with RigidSelective typeclass
rossabaker Dec 16, 2020
9079e16
Validated is rigid
rossabaker Dec 17, 2020
020a9fb
Revert "Validated is rigid" -- it's not rigid yet
rossabaker Dec 19, 2020
92f262f
Push select down to Apply
rossabaker Dec 19, 2020
762dd7d
Push branch and ifS down to Apply
rossabaker Dec 19, 2020
691144e
Push whenS down to Applicative
rossabaker Dec 19, 2020
3e31609
Push identity and distributivity laws to Applicative
rossabaker Dec 19, 2020
6b496ec
Remove Selective
rossabaker Dec 19, 2020
acce38c
Remove commented implicits
rossabaker Dec 20, 2020
7c78d54
RigidSelective default ap causes loops
rossabaker Dec 20, 2020
c4c1442
Add back lost selective associativity test
rossabaker Dec 20, 2020
3bcb791
Restate ifS skip laws to accommodate Under
rossabaker Dec 20, 2020
dba3dc0
Selective has re-entered the chat
rossabaker Dec 21, 2020
7a4d66a
Selective[ZipLazyList]
rossabaker Dec 21, 2020
6616707
Selective[Func] and RigidSelective[Func]
rossabaker Dec 21, 2020
bd0d4d9
Fix name of selective laws
rossabaker Dec 21, 2020
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
1 change: 0 additions & 1 deletion core/src/main/scala/cats/Applicative.scala
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ import scala.annotation.implicitNotFound
*/
def whenA[A](cond: Boolean)(f: => F[A]): F[Unit] =
if (cond) void(f) else unit

}

object Applicative {
Expand Down
8 changes: 7 additions & 1 deletion core/src/main/scala/cats/Monad.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ import scala.annotation.implicitNotFound
* Must obey the laws defined in cats.laws.MonadLaws.
*/
@implicitNotFound("Could not find an instance of Monad for ${F}")
@typeclass trait Monad[F[_]] extends FlatMap[F] with Applicative[F] {
@typeclass trait Monad[F[_]] extends FlatMap[F] with Selective[F] {
override def map[A, B](fa: F[A])(f: A => B): F[B] =
flatMap(fa)(a => pure(f(a)))

override def select[A, B](fab: F[Either[A, B]])(ff: F[A => B]): F[B] =
rossabaker marked this conversation as resolved.
Show resolved Hide resolved
flatMap(fab) {
case Left(a) => map(ff)(_(a))
case Right(b) => pure(b)
}

/**
* Execute an action repeatedly as long as the given `Boolean` expression
* returns `true`. The condition is evaluated before the loop body.
Expand Down
8 changes: 1 addition & 7 deletions core/src/main/scala/cats/MonadError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ package cats
*
* This type class allows one to abstract over error-handling monads.
*/
trait MonadError[F[_], E] extends ApplicativeError[F, E] with Monad[F] {

/**
* Turns a successful value into an error if it does not satisfy a given predicate.
*/
def ensure[A](fa: F[A])(error: => E)(predicate: A => Boolean): F[A] =
flatMap(fa)(a => if (predicate(a)) pure(a) else raiseError(error))
trait MonadError[F[_], E] extends SelectiveError[F, E] with Monad[F] {

/**
* Turns a successful value into an error specified by the `error` function if it does not satisfy a given predicate.
Expand Down
28 changes: 28 additions & 0 deletions core/src/main/scala/cats/Selective.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cats

import simulacrum.{typeclass}
import scala.annotation.implicitNotFound

@implicitNotFound("Could not find an instance of Selective for ${F}")
@typeclass trait Selective[F[_]] extends Applicative[F] {
rossabaker marked this conversation as resolved.
Show resolved Hide resolved
def select[A, B](fab: F[Either[A, B]])(ff: F[A => B]): F[B]
rossabaker marked this conversation as resolved.
Show resolved Hide resolved

def branch[A, B, C](x: F[Either[A, B]])(l: F[A => C])(r: F[B => C]): F[C] = {
val lhs = {
rossabaker marked this conversation as resolved.
Show resolved Hide resolved
val innerLhs: F[Either[A, Either[B, C]]] = map(x)(_.map(Left(_)))
val innerRhs: F[A => Either[B, C]] = map(l)(_.andThen(Right(_)))
select(innerLhs)(innerRhs)
}
select(lhs)(r)
}

def ifS[A](x: F[Boolean])(t: F[A])(e: F[A]): F[A] = {
rossabaker marked this conversation as resolved.
Show resolved Hide resolved
val condition: F[Either[Unit, Unit]] = map(x)(p => if (p) Left(()) else Right(()))
rossabaker marked this conversation as resolved.
Show resolved Hide resolved
val left: F[Unit => A] = map(t)(Function.const)
val right: F[Unit => A] = map(e)(Function.const)
branch(condition)(left)(right)
}

def whenS[A](fbool: F[Boolean])(fa: F[Unit]): F[Unit] =
ifS(fbool)(fa)(unit)
}
15 changes: 15 additions & 0 deletions core/src/main/scala/cats/SelectiveError.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cats

import cats.syntax.either._
rossabaker marked this conversation as resolved.
Show resolved Hide resolved

trait SelectiveError[F[_], E] extends ApplicativeError[F, E] with Selective[F] {
rossabaker marked this conversation as resolved.
Show resolved Hide resolved

/**
* Turns a successful value into an error if it does not satisfy a given predicate.
*/
def ensure[A](fa: F[A])(error: => E)(predicate: A => Boolean): F[A] =
rossabaker marked this conversation as resolved.
Show resolved Hide resolved
select(map(fa) { (a: A) =>
if (predicate(a)) Right(a)
else Either.leftUnit
})(raiseError(error))
}
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/data/EitherT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ abstract private[data] class EitherTInstances extends EitherTInstances1 {
implicit val monadEither: Monad[Either[E, *]] = cats.instances.either.catsStdInstancesForEither

def applicative: Applicative[Nested[P.F, Validated[E, *], *]] =
cats.data.Nested.catsDataApplicativeForNested(P.applicative, Validated.catsDataApplicativeErrorForValidated)
cats.data.Nested.catsDataApplicativeForNested(P.applicative, Validated.catsDataSelectiveErrorForValidated)

def monad: Monad[EitherT[M, E, *]] = cats.data.EitherT.catsDataMonadErrorForEitherT

Expand Down Expand Up @@ -983,7 +983,7 @@ abstract private[data] class EitherTInstances1 extends EitherTInstances2 {
new Parallel[EitherT[M, E, *]] {
type F[x] = Nested[M, Validated[E, *], x]

implicit val appValidated: Applicative[Validated[E, *]] = Validated.catsDataApplicativeErrorForValidated
implicit val appValidated: Applicative[Validated[E, *]] = Validated.catsDataSelectiveErrorForValidated
implicit val monadEither: Monad[Either[E, *]] = cats.instances.either.catsStdInstancesForEither

def applicative: Applicative[Nested[M, Validated[E, *], *]] =
Expand Down
28 changes: 22 additions & 6 deletions core/src/main/scala/cats/data/Validated.scala
Original file line number Diff line number Diff line change
Expand Up @@ -931,16 +931,19 @@ sealed abstract private[data] class ValidatedInstances extends ValidatedInstance
fab.leftMap(f)
}

implicit def catsDataApplicativeErrorForValidated[E](implicit E: Semigroup[E]): ApplicativeError[Validated[E, *], E] =
new ValidatedApplicative[E] with ApplicativeError[Validated[E, *], E] {

implicit def catsDataSelectiveErrorForValidated[E](implicit E: Semigroup[E]): SelectiveError[Validated[E, *], E] =
new ValidatedSelective[E] with SelectiveError[Validated[E, *], E] {
def handleErrorWith[A](fa: Validated[E, A])(f: E => Validated[E, A]): Validated[E, A] =
fa match {
case Validated.Invalid(e) => f(e)
case v @ Validated.Valid(_) => v
}
def raiseError[A](e: E): Validated[E, A] = Validated.Invalid(e)
}

@deprecated("Use catsDataSelectiveErrorForValidated", "2.4.0")
def catsDataApplicativeErrorForValidated[E](implicit E: Semigroup[E]): ApplicativeError[Validated[E, *], E] =
catsDataSelectiveErrorForValidated
}

sealed abstract private[data] class ValidatedInstances1 extends ValidatedInstances2 {
Expand All @@ -953,9 +956,13 @@ sealed abstract private[data] class ValidatedInstances1 extends ValidatedInstanc
def combine(x: Validated[A, B], y: Validated[A, B]): Validated[A, B] = x.combine(y)
}

implicit def catsDataCommutativeApplicativeForValidated[E: CommutativeSemigroup]
: CommutativeApplicative[Validated[E, *]] =
new ValidatedApplicative[E] with CommutativeApplicative[Validated[E, *]]
implicit def catsDataCommutativeSelectiveForValidated[E: CommutativeSemigroup]
: Selective[Validated[E, *]] with CommutativeApplicative[Validated[E, *]] =
new ValidatedSelective[E] with CommutativeApplicative[Validated[E, *]]

@deprecated("Use catsDataCommutativeSelectiveForValidated", "2.4.0")
def catsDataCommutativeApplicativeForValidated[E: CommutativeSemigroup]: CommutativeApplicative[Validated[E, *]] =
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's a CommutativeApplicative and a CommutativeMonad, we need to spend a few moments thinking about whether there's a CommutativeSelective.

catsDataCommutativeApplicativeForValidated

implicit def catsDataPartialOrderForValidated[A: PartialOrder, B: PartialOrder]: PartialOrder[Validated[A, B]] =
new PartialOrder[Validated[A, B]] {
Expand Down Expand Up @@ -1035,6 +1042,15 @@ sealed abstract private[data] class ValidatedInstances2 {
// scalastyle:off method.length
}

private[data] class ValidatedSelective[E: Semigroup] extends ValidatedApplicative[E] with Selective[Validated[E, *]] {
override def select[A, B](fab: Validated[E, Either[A, B]])(ff: Validated[E, A => B]): Validated[E, B] =
rossabaker marked this conversation as resolved.
Show resolved Hide resolved
rossabaker marked this conversation as resolved.
Show resolved Hide resolved
fab match {
case Valid(Left(a)) => ff.map(_(a))
case Valid(Right(b)) => Valid(b)
case i @ Invalid(_) => i
}
}

private[data] class ValidatedApplicative[E: Semigroup] extends CommutativeApplicative[Validated[E, *]] {
override def map[A, B](fa: Validated[E, A])(f: A => B): Validated[E, B] =
fa.map(f)
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/instances/either.scala
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ trait EitherInstances extends cats.kernel.instances.EitherInstances {
new Parallel[Either[E, *]] {
type F[x] = Validated[E, x]

def applicative: Applicative[Validated[E, *]] = Validated.catsDataApplicativeErrorForValidated
def applicative: Applicative[Validated[E, *]] = Validated.catsDataSelectiveErrorForValidated
def monad: Monad[Either[E, *]] = cats.instances.either.catsStdInstancesForEither

def sequential: Validated[E, *] ~> Either[E, *] =
Expand Down
1 change: 1 addition & 0 deletions core/src/main/scala/cats/syntax/all.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ trait AllSyntax
with PartialOrderSyntax
with ProfunctorSyntax
with ReducibleSyntax
with SelectiveSyntax
with SemigroupSyntax
with SemigroupKSyntax
with ShowSyntax
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/scala/cats/syntax/either.scala
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,11 @@ final class EitherObjectOps(private val either: Either.type) extends AnyVal { //
* Cached value of `Right(())` to avoid allocations for a common case.
*/
def unit[A]: Either[A, Unit] = EitherUtil.unit

/**
* Cached value of `Left(())` to avoid allocations for a common case.
*/
def leftUnit[B]: Either[Unit, B] = EitherUtil.leftUnit
rossabaker marked this conversation as resolved.
Show resolved Hide resolved
}

final class LeftOps[A, B](private val left: Left[A, B]) extends AnyVal {
Expand Down Expand Up @@ -509,4 +514,5 @@ private[cats] object EitherUtil {
left.asInstanceOf[Either[A, C]]

private[cats] val unit = Right(())
private[cats] val leftUnit = Left(())
rossabaker marked this conversation as resolved.
Show resolved Hide resolved
}
24 changes: 24 additions & 0 deletions core/src/main/scala/cats/syntax/selective.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cats
package syntax

trait SelectiveSyntax {
implicit final def catsSyntaxSelective[F[_], A, B](fab: F[Either[A, B]]): SelectiveOps[F, A, B] =
new SelectiveOps(fab)
implicit final def catsSyntaxIfS[F[_]](fBool: F[Boolean]): IfSOps[F] =
new IfSOps(fBool)
implicit final def catsSyntaxWhenS[F[_]](fBool: F[Boolean]): WhenSOps[F] =
new WhenSOps(fBool)
}

final class SelectiveOps[F[_], A, B](private val fab: F[Either[A, B]]) extends AnyVal {
def select(ff: F[A => B])(implicit F: Selective[F]): F[B] = F.select(fab)(ff)
def branch[C](l: F[A => C])(r: F[B => C])(implicit F: Selective[F]): F[C] = F.branch(fab)(l)(r)
}

final class IfSOps[F[_]](private val fBool: F[Boolean]) extends AnyVal {
def ifS[A](ifTrue: => F[A], ifFalse: => F[A])(implicit F: Selective[F]): F[A] = F.ifS(fBool)(ifTrue)(ifFalse)
}

final class WhenSOps[F[_]](private val fBool: F[Boolean]) extends AnyVal {
def whenS[A](fa: F[Unit])(implicit F: Selective[F]): F[Unit] = F.whenS(fBool)(fa)
}
11 changes: 10 additions & 1 deletion laws/src/main/scala/cats/laws/MonadLaws.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import cats.implicits._
/**
* Laws that must be obeyed by any `Monad`.
*/
trait MonadLaws[F[_]] extends ApplicativeLaws[F] with FlatMapLaws[F] {
trait MonadLaws[F[_]] extends SelectiveLaws[F] with FlatMapLaws[F] {
implicit override def F: Monad[F]

def monadLeftIdentity[A, B](a: A, f: A => F[B]): IsEq[F[B]] =
Expand Down Expand Up @@ -41,6 +41,15 @@ trait MonadLaws[F[_]] extends ApplicativeLaws[F] with FlatMapLaws[F] {
val res = F.tailRecM(0)(i => F.pure(if (i < n) Either.left(i + 1) else Either.right(i)))
res <-> F.pure(n)
}

def selectRigidity[A, B](fab: F[Either[A, B]], ff: F[A => B]): IsEq[F[B]] = {
def selectM[G[_]: Monad](gab: G[Either[A, B]])(gf: G[A => B]) =
gab.flatMap {
case Left(a) => gf.map(_(a))
case Right(b) => b.pure[G]
}
fab.select(ff) <-> selectM(fab)(ff)
}
}

object MonadLaws {
Expand Down
24 changes: 24 additions & 0 deletions laws/src/main/scala/cats/laws/SelectiveLaws.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cats
package laws

import cats.syntax.all._

/**
* Laws that must be obeyed by any `Selective`.
rossabaker marked this conversation as resolved.
Show resolved Hide resolved
*/
trait SelectiveLaws[F[_]] extends ApplicativeLaws[F] {
rossabaker marked this conversation as resolved.
Show resolved Hide resolved
implicit override def F: Selective[F]

def selectiveIdentity[A, B](faa: F[Either[A, A]]): IsEq[F[A]] =
faa.select(F.pure(identity)) <-> faa.map(_.merge)

def selectiveDistributivity[A, B](ab: Either[A, B], ff1: F[A => B], ff2: F[A => B]): IsEq[F[B]] =
F.pure(ab).select(ff1 *> ff2) <-> F.pure(ab).select(ff1) *> F.pure(ab).select(ff2)

// TODO associativity
}

object SelectiveLaws {
def apply[F[_]](implicit ev: Selective[F]): SelectiveLaws[F] =
new SelectiveLaws[F] { def F: Selective[F] = ev }
}
28 changes: 22 additions & 6 deletions laws/src/main/scala/cats/laws/discipline/MonadTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ package discipline

import cats.laws.discipline.SemigroupalTests.Isomorphisms
import cats.platform.Platform
import org.scalacheck.{Arbitrary, Cogen, Prop}
import cats.syntax.all._
import org.scalacheck.{Arbitrary, Cogen, Gen, Prop}
import Prop._

trait MonadTests[F[_]] extends ApplicativeTests[F] with FlatMapTests[F] {
trait MonadTests[F[_]] extends SelectiveTests[F] with FlatMapTests[F] {
def laws: MonadLaws[F]

def monad[A: Arbitrary: Eq, B: Arbitrary: Eq, C: Arbitrary: Eq](implicit
Expand All @@ -25,11 +26,18 @@ trait MonadTests[F[_]] extends ApplicativeTests[F] with FlatMapTests[F] {
EqFABC: Eq[F[(A, B, C)]],
EqFInt: Eq[F[Int]],
iso: Isomorphisms[F]
): RuleSet =
): RuleSet = {
implicit def ArbFAA: Arbitrary[F[Either[A, A]]] =
Arbitrary(
Gen.oneOf(ArbFA.arbitrary.map(fa => laws.F.map(fa)(_.asLeft[A])),
ArbFA.arbitrary.map(fa => laws.F.map(fa)(_.asRight[A]))
)
)
rossabaker marked this conversation as resolved.
Show resolved Hide resolved

new RuleSet {
def name: String = "monad"
def bases: Seq[(String, RuleSet)] = Nil
def parents: Seq[RuleSet] = Seq(applicative[A, B, C], flatMap[A, B, C])
def parents: Seq[RuleSet] = Seq(selective[A, B, C], flatMap[A, B, C])
def props: Seq[(String, Prop)] =
Seq(
"monad left identity" -> forAll(laws.monadLeftIdentity[A, B] _),
Expand All @@ -38,6 +46,7 @@ trait MonadTests[F[_]] extends ApplicativeTests[F] with FlatMapTests[F] {
) ++ (if (Platform.isJvm) Seq[(String, Prop)]("tailRecM stack safety" -> Prop.lzy(laws.tailRecMStackSafety))
else Seq.empty)
}
}

def stackUnsafeMonad[A: Arbitrary: Eq, B: Arbitrary: Eq, C: Arbitrary: Eq](implicit
ArbFA: Arbitrary[F[A]],
Expand All @@ -54,18 +63,25 @@ trait MonadTests[F[_]] extends ApplicativeTests[F] with FlatMapTests[F] {
EqFABC: Eq[F[(A, B, C)]],
EqFInt: Eq[F[Int]],
iso: Isomorphisms[F]
): RuleSet =
): RuleSet = {
implicit def ArbFAA: Arbitrary[F[Either[A, A]]] =
Arbitrary(
Gen.oneOf(ArbFA.arbitrary.map(fa => laws.F.map(fa)(_.asLeft[A])),
ArbFA.arbitrary.map(fa => laws.F.map(fa)(_.asRight[A]))
)
)
new RuleSet {
def name: String = "monad (stack-unsafe)"
def bases: Seq[(String, RuleSet)] = Nil
def parents: Seq[RuleSet] = Seq(applicative[A, B, C], flatMap[A, B, C])
def parents: Seq[RuleSet] = Seq(selective[A, B, C], flatMap[A, B, C])
def props: Seq[(String, Prop)] =
Seq(
"monad left identity" -> forAll(laws.monadLeftIdentity[A, B] _),
"monad right identity" -> forAll(laws.monadRightIdentity[A] _),
"map flatMap coherence" -> forAll(laws.mapFlatMapCoherence[A, B] _)
)
}
}
}

object MonadTests {
Expand Down
46 changes: 46 additions & 0 deletions laws/src/main/scala/cats/laws/discipline/SelectiveTests.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package cats
package laws
package discipline

import cats.laws.discipline.SemigroupalTests.Isomorphisms
import org.scalacheck.{Arbitrary, Cogen, Prop}
import Prop._

trait SelectiveTests[F[_]] extends ApplicativeTests[F] {
def laws: SelectiveLaws[F]

def selective[A: Arbitrary: Eq, B: Arbitrary: Eq, C: Arbitrary: Eq](implicit
ArbFA: Arbitrary[F[A]],
ArbFB: Arbitrary[F[B]],
ArbFC: Arbitrary[F[C]],
ArbFAtoB: Arbitrary[F[A => B]],
ArbFBtoC: Arbitrary[F[B => C]],
ArbFAA: Arbitrary[F[Either[A, A]]],
CogenA: Cogen[A],
CogenB: Cogen[B],
CogenC: Cogen[C],
EqFA: Eq[F[A]],
EqFB: Eq[F[B]],
EqFC: Eq[F[C]],
EqFABC: Eq[F[(A, B, C)]],
EqFInt: Eq[F[Int]],
iso: Isomorphisms[F]
): RuleSet = {
new RuleSet {
def name: String = "selective"
def bases: Seq[(String, RuleSet)] = Nil
def parents: Seq[RuleSet] = Seq(applicative[A, B, C])
def props: Seq[(String, Prop)] =
Seq(
"selective identity" -> forAll(laws.selectiveIdentity[A, B] _)
)
}
}
}

object SelectiveTests {
def apply[F[_]: Selective]: SelectiveTests[F] =
new SelectiveTests[F] {
def laws: SelectiveLaws[F] = SelectiveLaws[F]
}
}