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

Make composed instanes for binary type classes consisted with the una… #1133

Merged
merged 1 commit into from
Jun 15, 2016
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions core/src/main/scala/cats/Bifoldable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ trait Bifoldable[F[_, _]] extends Any with Serializable { self =>
)

def compose[G[_, _]](implicit ev: Bifoldable[G]): Bifoldable[λ[(α, β) => F[G[α, β], G[α, β]]]] =
new CompositeBifoldable[F, G] {
new ComposedBifoldable[F, G] {
val F = self
val G = ev
}
Expand All @@ -28,17 +28,17 @@ object Bifoldable {
def apply[F[_, _]](implicit F: Bifoldable[F]): Bifoldable[F] = F
}

trait CompositeBifoldable[F[_, _], G[_, _]] extends Bifoldable[λ[(α, β) => F[G[α, β], G[α, β]]]] {
private[cats] trait ComposedBifoldable[F[_, _], G[_, _]] extends Bifoldable[λ[(α, β) => F[G[α, β], G[α, β]]]] {
implicit def F: Bifoldable[F]
implicit def G: Bifoldable[G]

def bifoldLeft[A, B, C](fab: F[G[A, B], G[A, B]], c: C)(f: (C, A) => C, g: (C, B) => C): C =
override def bifoldLeft[A, B, C](fab: F[G[A, B], G[A, B]], c: C)(f: (C, A) => C, g: (C, B) => C): C =
F.bifoldLeft(fab, c)(
(c: C, gab: G[A, B]) => G.bifoldLeft(gab, c)(f, g),
(c: C, gab: G[A, B]) => G.bifoldLeft(gab, c)(f, g)
)

def bifoldRight[A, B, C](fab: F[G[A, B], G[A, B]], c: Eval[C])(f: (A, Eval[C]) => Eval[C], g: (B, Eval[C]) => Eval[C]): Eval[C] =
override def bifoldRight[A, B, C](fab: F[G[A, B], G[A, B]], c: Eval[C])(f: (A, Eval[C]) => Eval[C], g: (B, Eval[C]) => Eval[C]): Eval[C] =
F.bifoldRight(fab, c)(
(gab: G[A, B], c: Eval[C]) => G.bifoldRight(gab, c)(f, g),
(gab: G[A, B], c: Eval[C]) => G.bifoldRight(gab, c)(f, g)
Expand Down
11 changes: 6 additions & 5 deletions core/src/main/scala/cats/Bitraverse.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cats

import cats.functor.Bifunctor
import cats.functor.{Bifunctor, ComposedBifunctor}

/**
* A type class abstracting over types that give rise to two independent [[cats.Traverse]]s.
Expand All @@ -15,7 +15,7 @@ trait Bitraverse[F[_, _]] extends Bifoldable[F] with Bifunctor[F] { self =>

/** If F and G are both [[cats.Bitraverse]] then so is their composition F[G[_, _], G[_, _]] */
def compose[G[_, _]](implicit ev: Bitraverse[G]): Bitraverse[λ[(α, β) => F[G[α, β], G[α, β]]]] =
new CompositeBitraverse[F, G] {
new ComposedBitraverse[F, G] {
val F = self
val G = ev
}
Expand All @@ -28,13 +28,14 @@ object Bitraverse {
def apply[F[_, _]](implicit F: Bitraverse[F]): Bitraverse[F] = F
}

trait CompositeBitraverse[F[_, _], G[_, _]]
private[cats] trait ComposedBitraverse[F[_, _], G[_, _]]
extends Bitraverse[λ[(α, β) => F[G[α, β], G[α, β]]]]
with CompositeBifoldable[F, G] {
with ComposedBifoldable[F, G]
with ComposedBifunctor[F,G] {
def F: Bitraverse[F]
def G: Bitraverse[G]

def bitraverse[H[_]: Applicative, A, B, C, D](
override def bitraverse[H[_]: Applicative, A, B, C, D](
fab: F[G[A, B], G[A, B]])(
f: A => H[C], g: B => H[D]
): H[F[G[C, D], G[C, D]]] =
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/scala/cats/functor/Bifunctor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ trait Bifunctor[F[_, _]] extends Any with Serializable { self =>

/** The composition of two Bifunctors is itself a Bifunctor */
def compose[G[_, _]](implicit G0: Bifunctor[G]): Bifunctor[λ[(α, β) => F[G[α, β], G[α, β]]]] =
new CompositeBifunctor[F, G] {
new ComposedBifunctor[F, G] {
val F = self
val G = G0
}
Expand All @@ -36,12 +36,12 @@ object Bifunctor {
def apply[F[_, _]](implicit ev: Bifunctor[F]): Bifunctor[F] = ev
}

trait CompositeBifunctor[F[_, _], G[_, _]]
private[cats] trait ComposedBifunctor[F[_, _], G[_, _]]
extends Bifunctor[λ[(A, B) => F[G[A, B], G[A, B]]]] {
def F: Bifunctor[F]
def G: Bifunctor[G]

def bimap[A, B, C, D](fab: F[G[A, B], G[A, B]])(f: A => C, g: B => D): F[G[C, D], G[C, D]] = {
override def bimap[A, B, C, D](fab: F[G[A, B], G[A, B]])(f: A => C, g: B => D): F[G[C, D], G[C, D]] = {
val innerBimap: G[A, B] => G[C, D] = gab => G.bimap(gab)(f, g)
F.bimap(fab)(innerBimap, innerBimap)
}
Expand Down