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

Add Tuple2K Semigroupal #3502

Merged
merged 3 commits into from
Jul 2, 2020
Merged
Changes from all commits
Commits
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
23 changes: 20 additions & 3 deletions core/src/main/scala/cats/data/Tuple2K.scala
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,22 @@ sealed abstract private[data] class Tuple2KInstances8 {
def F: Functor[F] = FF
def G: Functor[G] = GG
}
implicit def catsDataSemigroupalForTuple2K[F[_], G[_]](implicit
FF: Semigroupal[F],
GG: Semigroupal[G]
): Semigroupal[λ[α => Tuple2K[F, G, α]]] =
rmehri01 marked this conversation as resolved.
Show resolved Hide resolved
new Tuple2KSemigroupal[F, G] {
def F: Semigroupal[F] = FF
def G: Semigroupal[G] = GG
}
}

sealed private[data] trait Tuple2KSemigroupal[F[_], G[_]] extends Semigroupal[λ[α => Tuple2K[F, G, α]]] {
def F: Semigroupal[F]
def G: Semigroupal[G]

override def product[A, B](fa: Tuple2K[F, G, A], fb: Tuple2K[F, G, B]): Tuple2K[F, G, (A, B)] =
Tuple2K(F.product(fa.first, fb.first), G.product(fa.second, fb.second))
}

sealed private[data] trait Tuple2KFunctor[F[_], G[_]] extends Functor[λ[α => Tuple2K[F, G, α]]] {
Expand Down Expand Up @@ -233,13 +249,14 @@ sealed private[data] trait Tuple2KContravariantMonoidal[F[_], G[_]]
Tuple2K(F.contramap(fa.first)(f), G.contramap(fa.second)(f))
}

sealed private[data] trait Tuple2KApply[F[_], G[_]] extends Apply[λ[α => Tuple2K[F, G, α]]] with Tuple2KFunctor[F, G] {
sealed private[data] trait Tuple2KApply[F[_], G[_]]
extends Apply[λ[α => Tuple2K[F, G, α]]]
with Tuple2KFunctor[F, G]
with Tuple2KSemigroupal[F, G] {
def F: Apply[F]
def G: Apply[G]
override def ap[A, B](f: Tuple2K[F, G, A => B])(fa: Tuple2K[F, G, A]): Tuple2K[F, G, B] =
Tuple2K(F.ap(f.first)(fa.first), G.ap(f.second)(fa.second))
override def product[A, B](fa: Tuple2K[F, G, A], fb: Tuple2K[F, G, B]): Tuple2K[F, G, (A, B)] =
Tuple2K(F.product(fa.first, fb.first), G.product(fa.second, fb.second))
override def map2Eval[A, B, Z](fa: Tuple2K[F, G, A], fb: Eval[Tuple2K[F, G, B]])(
f: (A, B) => Z
): Eval[Tuple2K[F, G, Z]] = {
Expand Down