Skip to content

Commit

Permalink
renamed Cartesian to Semigroupal
Browse files Browse the repository at this point in the history
  • Loading branch information
kailuowang committed Oct 10, 2017
1 parent 8cce29c commit de6345e
Show file tree
Hide file tree
Showing 79 changed files with 258 additions and 255 deletions.
4 changes: 2 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -723,9 +723,9 @@ previously been provided by `Apply`, you'll need to change your imports from
`cats.syntax.apply._` to `cats.syntax.cartesian._`. For example:

```scala
scala> import cats.Eval, cats.syntax.cartesian._
scala> import cats.Eval, cats.syntax.semigroupal._
import cats.Eval
import cats.syntax.cartesian._
import cats.syntax.semigroupal._

scala> (Eval.now("v") |@| Eval.now(0.4)).tupled
res0: cats.Eval[(String, Double)] = cats.Eval$$anon$5@104f8bbd
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/Apply.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import simulacrum.typeclass
* Must obey the laws defined in cats.laws.ApplyLaws.
*/
@typeclass(excludeParents = List("ApplyArityFunctions"))
trait Apply[F[_]] extends Functor[F] with Cartesian[F] with ApplyArityFunctions[F] { self =>
trait Apply[F[_]] extends Functor[F] with Semigroupal[F] with ApplyArityFunctions[F] { self =>

/**
* Given a value and a function in the Apply context, applies the
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/Composed.scala
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ private[cats] trait ComposedContravariantCovariant[F[_], G[_]] extends Contravar
F.contramap(fga)(gb => G.map(gb)(f))
}

private[cats] trait ComposedCartesian[F[_], G[_]] extends ContravariantCartesian[λ[α => F[G[α]]]] with ComposedContravariantCovariant[F, G] { outer =>
def F: ContravariantCartesian[F]
private[cats] trait ComposedSemigroupal[F[_], G[_]] extends ContravariantSemigroupal[λ[α => F[G[α]]]] with ComposedContravariantCovariant[F, G] { outer =>
def F: ContravariantSemigroupal[F]
def G: Functor[G]

def product[A, B](fa: F[G[A]], fb: F[G[B]]): F[G[(A, B)]] =
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/scala/cats/ContravariantCartesian.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package cats
import simulacrum.typeclass

/**
* [[ContravariantCartesian]] is nothing more than something both contravariant
* and Cartesian. It comes up enough to be useful, and composes well
* [[ContravariantSemigroupal]] is nothing more than something both contravariant
* and Semigroupal. It comes up enough to be useful, and composes well
*/
@typeclass trait ContravariantCartesian[F[_]] extends Cartesian[F] with Contravariant[F] { self =>
override def composeFunctor[G[_]: Functor]: ContravariantCartesian[λ[α => F[G[α]]]] =
new ComposedCartesian[F, G] {
@typeclass trait ContravariantSemigroupal[F[_]] extends Semigroupal[F] with Contravariant[F] { self =>
override def composeFunctor[G[_]: Functor]: ContravariantSemigroupal[λ[α => F[G[α]]]] =
new ComposedSemigroupal[F, G] {
def F = self
def G = Functor[G]
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/InvariantMonoidal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import simulacrum.typeclass
*
* Must obey the laws defined in cats.laws.InvariantMonoidalLaws.
*/
@typeclass trait InvariantMonoidal[F[_]] extends Invariant[F] with Cartesian[F] {
@typeclass trait InvariantMonoidal[F[_]] extends Invariant[F] with Semigroupal[F] {
def pure[A](a: A): F[A]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ package cats
import simulacrum.typeclass

/**
* [[Cartesian]] captures the idea of composing independent effectful values.
* [[Semigroupal]] captures the idea of composing independent effectful values.
* It is of particular interest when taken together with [[Functor]] - where [[Functor]]
* captures the idea of applying a unary pure function to an effectful value,
* calling `product` with `map` allows one to apply a function of arbitrary arity to multiple
* independent effectful values.
*
* That same idea is also manifested in the form of [[Apply]], and indeed [[Apply]] extends both
* [[Cartesian]] and [[Functor]] to illustrate this.
* [[Semigroupal]] and [[Functor]] to illustrate this.
*/
@typeclass trait Cartesian[F[_]] {
@typeclass trait Semigroupal[F[_]] {
def product[A, B](fa: F[A], fb: F[B]): F[(A, B)]
}

object Cartesian extends CartesianArityFunctions
object Semigroupal extends SemigroupalArityFunctions
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/instances/eq.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package cats
package instances

trait EqInstances {
implicit val catsContravariantCartesianForEq: ContravariantCartesian[Eq] =
new ContravariantCartesian[Eq] {
implicit val catsContravariantSemigroupalForEq: ContravariantSemigroupal[Eq] =
new ContravariantSemigroupal[Eq] {
def contramap[A, B](fa: Eq[A])(fn: B => A): Eq[B] =
fa.on(fn)
def product[A, B](fa: Eq[A], fb: Eq[B]): Eq[(A, B)] =
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/instances/equiv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package cats
package instances

trait EquivInstances {
implicit val catsContravariantCartesianEquiv: ContravariantCartesian[Equiv] =
new ContravariantCartesian[Equiv] {
implicit val catsContravariantSemigroupalEquiv: ContravariantSemigroupal[Equiv] =
new ContravariantSemigroupal[Equiv] {
def contramap[A, B](fa: Equiv[A])(f: B => A): Equiv[B] =
new Equiv[B] {
def equiv(x: B, y: B): Boolean = fa.equiv(f(x), f(y))
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/instances/order.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package instances

trait OrderInstances extends cats.kernel.OrderToOrderingConversion {

implicit val catsContravariantCartesianForOrder: ContravariantCartesian[Order] =
new ContravariantCartesian[Order] {
implicit val catsContravariantSemigroupalForOrder: ContravariantSemigroupal[Order] =
new ContravariantSemigroupal[Order] {
/** Derive an `Order` for `B` given an `Order[A]` and a function `B => A`.
*
* Note: resulting instances are law-abiding only when the functions used are injective (represent a one-to-one mapping)
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/instances/ordering.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package instances

trait OrderingInstances {

implicit val catsContravariantCartesianForOrdering: ContravariantCartesian[Ordering] =
new ContravariantCartesian[Ordering] {
implicit val catsContravariantSemigroupalForOrdering: ContravariantSemigroupal[Ordering] =
new ContravariantSemigroupal[Ordering] {
/** Derive an `Ordering` for `B` given an `Ordering[A]` and a function `B => A`.
*
* Note: resulting instances are law-abiding only when the functions used are injective (represent a one-to-one mapping)
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/instances/partialOrder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package cats
package instances

trait PartialOrderInstances {
implicit val catsContravariantCartesianForPartialOrder: ContravariantCartesian[PartialOrder] =
new ContravariantCartesian[PartialOrder] {
implicit val catsContravariantSemigroupalForPartialOrder: ContravariantSemigroupal[PartialOrder] =
new ContravariantSemigroupal[PartialOrder] {
/** Derive a `PartialOrder` for `B` given a `PartialOrder[A]` and a function `B => A`.
*
* Note: resulting instances are law-abiding only when the functions used are injective (represent a one-to-one mapping)
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/instances/partialOrdering.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package cats
package instances

trait PartialOrderingInstances {
implicit val catsContravariantCartesianForPartialOrdering: ContravariantCartesian[PartialOrdering] =
new ContravariantCartesian[PartialOrdering] {
implicit val catsContravariantSemigroupalForPartialOrdering: ContravariantSemigroupal[PartialOrdering] =
new ContravariantSemigroupal[PartialOrdering] {
/** Derive a `PartialOrdering` for `B` given a `PartialOrdering[A]` and a function `B => A`.
*
* Note: resulting instances are law-abiding only when the functions used are injective (represent a one-to-one mapping)
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/scala/cats/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,7 @@ package object cats {
val Semigroup = cats.kernel.Semigroup
val Monoid = cats.kernel.Monoid
val Group = cats.kernel.Group

@deprecated("renamed to Semigroupal", "1.0.0-RC1")
type Cartesian[F[_]] = Semigroupal[F]
}
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/syntax/all.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ trait AllSyntax
with BifunctorSyntax
with BifoldableSyntax
with BitraverseSyntax
with CartesianSyntax
with SemigroupalSyntax
with CoflatMapSyntax
with ComonadSyntax
with ComposeSyntax
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/syntax/apply.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cats
package syntax

trait ApplySyntax extends TupleCartesianSyntax {
trait ApplySyntax extends TupleSemigroupalSyntax {
implicit final def catsSyntaxApply[F[_], A](fa: F[A])(implicit F: Apply[F]): Apply.Ops[F, A] =
new Apply.Ops[F, A] {
type TypeClassType = Apply[F]
Expand Down
20 changes: 0 additions & 20 deletions core/src/main/scala/cats/syntax/cartesian.scala

This file was deleted.

2 changes: 1 addition & 1 deletion core/src/main/scala/cats/syntax/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package object syntax {
object bifunctor extends BifunctorSyntax
object bifoldable extends BifoldableSyntax
object bitraverse extends BitraverseSyntax
object cartesian extends CartesianSyntax
object semigroupal extends SemigroupalSyntax
object coflatMap extends CoflatMapSyntax
object eitherK extends EitherKSyntax
object comonad extends ComonadSyntax
Expand Down
20 changes: 20 additions & 0 deletions core/src/main/scala/cats/syntax/semigroupal.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cats
package syntax

trait SemigroupalSyntax {
implicit final def catsSyntaxSemigroupal[F[_], A](fa: F[A])(implicit F: Semigroupal[F]): SemigroupalOps[F, A] =
new SemigroupalOps[F, A] {
type TypeClassType = Semigroupal[F]

val self = fa
val typeClassInstance = F
}
}

abstract class SemigroupalOps[F[_], A] extends Semigroupal.Ops[F, A] {

@deprecated("Replaced by an apply syntax, e.g. instead of (a |@| b).map(...) use (a, b).mapN(...)", "1.0.0-MF")
final def |@|[B](fb: F[B]): SemigroupalBuilder[F]#SemigroupalBuilder2[A, B] =
new SemigroupalBuilder[F] |@| self |@| fb

}
2 changes: 1 addition & 1 deletion docs/src/main/tut/datatypes/validated.md
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ implicit def validatedApplicative[E : Semigroup]: Applicative[Validated[E, ?]] =
```

Awesome! And now we also get access to all the goodness of `Applicative`, which includes `map{2-22}`, as well as the
`Cartesian` tuple syntax.
`Semigroupal` tuple syntax.

We can now easily ask for several bits of configuration and get any and all errors returned back.

Expand Down
2 changes: 1 addition & 1 deletion docs/src/main/tut/typeclasses/invariantmonoidal.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def product[A, B](fa: Semigroup[A], fb: Semigroup[B]): Semigroup[(A, B)] =
}
```

Given an instance of `InvariantMonoidal` for `Semigroup`, we are able to combine existing `Semigroup` instances to form a new `Semigroup` by using the `Cartesian` syntax:
Given an instance of `InvariantMonoidal` for `Semigroup`, we are able to combine existing `Semigroup` instances to form a new `Semigroup` by using the `Semigroupal` syntax:

```tut:silent
import cats.implicits._
Expand Down
4 changes: 2 additions & 2 deletions free/src/test/scala/cats/free/CofreeTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cats
package free

import cats.data.{NonEmptyList, OptionT}
import cats.laws.discipline.{CartesianTests, ComonadTests, ReducibleTests, SerializableTests, TraverseTests}
import cats.laws.discipline.{SemigroupalTests, ComonadTests, ReducibleTests, SerializableTests, TraverseTests}
import cats.syntax.list._
import cats.tests.{CatsSuite, Spooky}
import org.scalacheck.{Arbitrary, Cogen, Gen}
Expand All @@ -11,7 +11,7 @@ class CofreeTests extends CatsSuite {

import CofreeTests._

implicit val iso = CartesianTests.Isomorphisms.invariant[Cofree[Option, ?]]
implicit val iso = SemigroupalTests.Isomorphisms.invariant[Cofree[Option, ?]]

checkAll("Cofree[Option, ?]", ComonadTests[Cofree[Option, ?]].comonad[Int, Int, Int])
locally {
Expand Down
4 changes: 2 additions & 2 deletions free/src/test/scala/cats/free/FreeApplicativeTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package free

import cats.tests.CatsSuite
import cats.arrow.FunctionK
import cats.laws.discipline.{CartesianTests, ApplicativeTests, SerializableTests}
import cats.laws.discipline.{SemigroupalTests, ApplicativeTests, SerializableTests}
import cats.data.State

import org.scalacheck.{Arbitrary, Gen}

class FreeApplicativeTests extends CatsSuite {
import FreeApplicativeTests._

implicit val iso = CartesianTests.Isomorphisms.invariant[FreeApplicative[Option, ?]]
implicit val iso = SemigroupalTests.Isomorphisms.invariant[FreeApplicative[Option, ?]]

checkAll("FreeApplicative[Option, ?]", ApplicativeTests[FreeApplicative[Option, ?]].applicative[Int, Int, Int])
checkAll("Applicative[FreeApplicative[Option, ?]]", SerializableTests.serializable(Applicative[FreeApplicative[Option, ?]]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package tests
import cats.arrow.FunctionK
import cats.free.FreeInvariantMonoidal
import cats.laws.discipline.{InvariantMonoidalTests, SerializableTests}
import cats.laws.discipline.CartesianTests.Isomorphisms
import cats.laws.discipline.SemigroupalTests.Isomorphisms
import org.scalacheck.{Arbitrary, Gen}
import cats.tests.CsvCodecInvariantMonoidalTests._

Expand Down
6 changes: 3 additions & 3 deletions free/src/test/scala/cats/free/FreeTTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,17 @@ trait FreeTTestsInstances {
import IndexedStateT._
import cats.kernel.instances.option._
import cats.tests.IndexedStateTTests._
import CartesianTests._
import SemigroupalTests._

type IntState[A] = State[Int, A]
type FreeTOption[A] = FreeT[Option, Option, A]
type FreeTState[A] = FreeT[IntState, IntState, A]

case class JustFunctor[A](a: A)

implicit val ftlWIso: Isomorphisms[FreeTOption] = CartesianTests.Isomorphisms.invariant[FreeTOption]
implicit val ftlWIso: Isomorphisms[FreeTOption] = SemigroupalTests.Isomorphisms.invariant[FreeTOption]

implicit val ftlSIso: Isomorphisms[FreeTState] = CartesianTests.Isomorphisms.invariant[FreeTState]
implicit val ftlSIso: Isomorphisms[FreeTState] = SemigroupalTests.Isomorphisms.invariant[FreeTState]

implicit val jfFunctor: Functor[JustFunctor] = new Functor[JustFunctor] {
override def map[A, B](fa: JustFunctor[A])(f: A => B): JustFunctor[B] = JustFunctor(f(fa.a))
Expand Down
4 changes: 2 additions & 2 deletions free/src/test/scala/cats/free/FreeTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package free

import cats.arrow.FunctionK
import cats.data.EitherK
import cats.laws.discipline.{CartesianTests, FoldableTests, MonadTests, SerializableTests, TraverseTests}
import cats.laws.discipline.{SemigroupalTests, FoldableTests, MonadTests, SerializableTests, TraverseTests}
import cats.laws.discipline.arbitrary.catsLawsArbitraryForFn0
import cats.tests.CatsSuite

Expand All @@ -13,7 +13,7 @@ import Arbitrary.arbFunction1
class FreeTests extends CatsSuite {
import FreeTests._

implicit val iso = CartesianTests.Isomorphisms.invariant[Free[Option, ?]]
implicit val iso = SemigroupalTests.Isomorphisms.invariant[Free[Option, ?]]

checkAll("Free[Option, ?]", MonadTests[Free[Option, ?]].monad[Int, Int, Int])
checkAll("Monad[Free[Option, ?]]", SerializableTests.serializable(Monad[Free[Option, ?]]))
Expand Down
2 changes: 1 addition & 1 deletion laws/src/main/scala/cats/laws/ApplicativeLaws.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ trait ApplicativeLaws[F[_]] extends ApplyLaws[F] {
F.unit.map(_ => a) <-> F.pure(a)

// The following are the lax monoidal functor identity laws - the associativity law is covered by
// Cartesian's associativity law.
// Semigroupal's associativity law.

def monoidalLeftIdentity[A](fa: F[A]): (F[(Unit, A)], F[A]) =
(F.product(F.pure(()), fa), fa)
Expand Down
2 changes: 1 addition & 1 deletion laws/src/main/scala/cats/laws/ApplyLaws.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import cats.syntax.functor._
/**
* Laws that must be obeyed by any `Apply`.
*/
trait ApplyLaws[F[_]] extends FunctorLaws[F] with CartesianLaws[F] {
trait ApplyLaws[F[_]] extends FunctorLaws[F] with SemigroupalLaws[F] {
implicit override def F: Apply[F]

def applyComposition[A, B, C](fa: F[A], fab: F[A => B], fbc: F[B => C]): IsEq[F[C]] = {
Expand Down
17 changes: 0 additions & 17 deletions laws/src/main/scala/cats/laws/CartesianLaws.scala

This file was deleted.

4 changes: 2 additions & 2 deletions laws/src/main/scala/cats/laws/InvariantMonoidalLaws.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ package laws
/**
* Laws that must be obeyed by any `cats.InvariantMonoidal`.
*/
trait InvariantMonoidalLaws[F[_]] extends InvariantLaws[F] with CartesianLaws[F] {
trait InvariantMonoidalLaws[F[_]] extends InvariantLaws[F] with SemigroupalLaws[F] {
override implicit def F: InvariantMonoidal[F]
import cats.syntax.cartesian._
import cats.syntax.semigroupal._
import cats.syntax.invariant._

def invariantMonoidalLeftIdentity[A, B](fa: F[A], b: B): IsEq[F[A]] =
Expand Down
17 changes: 17 additions & 0 deletions laws/src/main/scala/cats/laws/SemigroupalLaws.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cats
package laws

/**
* Laws that must be obeyed by any `cats.Semigroupal`.
*/
trait SemigroupalLaws[F[_]] {
implicit def F: Semigroupal[F]

def semigroupalAssociativity[A, B, C](fa: F[A], fb: F[B], fc: F[C]): (F[(A, (B, C))], F[((A, B), C)]) =
(F.product(fa, F.product(fb, fc)), F.product(F.product(fa, fb), fc))
}

object SemigroupalLaws {
def apply[F[_]](implicit ev: Semigroupal[F]): SemigroupalLaws[F] =
new SemigroupalLaws[F] { val F = ev }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cats
package laws
package discipline

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

Expand Down
Loading

0 comments on commit de6345e

Please sign in to comment.