Skip to content

Commit

Permalink
Rename prod coproduct (#1589)
Browse files Browse the repository at this point in the history
* renamed Coproduct and Prod to EitherK and Tuple2K in code

* renamed files accordingly
  • Loading branch information
kailuowang committed Apr 5, 2017
1 parent dbe4407 commit 2a32e37
Show file tree
Hide file tree
Showing 23 changed files with 663 additions and 663 deletions.
18 changes: 9 additions & 9 deletions core/src/main/scala/cats/Inject.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cats

import cats.arrow.FunctionK
import cats.data.Coproduct
import cats.data.EitherK

/**
* Inject type class as described in "Data types a la carte" (Swierstra 2008).
Expand All @@ -26,18 +26,18 @@ private[cats] sealed abstract class InjectInstances {
val prj = λ[FunctionK[F, λ[α => Option[F[α]]]]](Some(_))
}

implicit def catsLeftInjectInstance[F[_], G[_]]: Inject[F, Coproduct[F, G, ?]] =
new Inject[F, Coproduct[F, G, ?]] {
val inj = λ[FunctionK[F, Coproduct[F, G, ?]]](Coproduct.leftc(_))
implicit def catsLeftInjectInstance[F[_], G[_]]: Inject[F, EitherK[F, G, ?]] =
new Inject[F, EitherK[F, G, ?]] {
val inj = λ[FunctionK[F, EitherK[F, G, ?]]](EitherK.leftc(_))

val prj = λ[FunctionK[Coproduct[F, G, ?], λ[α => Option[F[α]]]]](_.run.left.toOption)
val prj = λ[FunctionK[EitherK[F, G, ?], λ[α => Option[F[α]]]]](_.run.left.toOption)
}

implicit def catsRightInjectInstance[F[_], G[_], H[_]](implicit I: Inject[F, G]): Inject[F, Coproduct[H, G, ?]] =
new Inject[F, Coproduct[H, G, ?]] {
val inj = λ[FunctionK[G, Coproduct[H, G, ?]]](Coproduct.rightc(_)) compose I.inj
implicit def catsRightInjectInstance[F[_], G[_], H[_]](implicit I: Inject[F, G]): Inject[F, EitherK[H, G, ?]] =
new Inject[F, EitherK[H, G, ?]] {
val inj = λ[FunctionK[G, EitherK[H, G, ?]]](EitherK.rightc(_)) compose I.inj

val prj = λ[FunctionK[Coproduct[H, G, ?], λ[α => Option[F[α]]]]](_.run.right.toOption.flatMap(I.prj(_)))
val prj = λ[FunctionK[EitherK[H, G, ?], λ[α => Option[F[α]]]]](_.run.right.toOption.flatMap(I.prj(_)))
}
}

Expand Down
16 changes: 8 additions & 8 deletions core/src/main/scala/cats/arrow/FunctionK.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cats
package arrow

import cats.data.{Coproduct, Prod}
import cats.data.{EitherK, Tuple2K}

import cats.macros.MacroCompat

Expand Down Expand Up @@ -38,29 +38,29 @@ trait FunctionK[F[_], G[_]] extends Serializable { self =>

/**
* Composes two instances of FunctionK into a new FunctionK that transforms
* a [[cats.data.Coproduct]] to a single functor.
* a [[cats.data.EitherK]] to a single functor.
*
* This transformation will be used to transform left `F` values while
* `h` will be used to transform right `H` values.
*/
def or[H[_]](h: FunctionK[H, G]): FunctionK[Coproduct[F, H, ?], G] =
λ[FunctionK[Coproduct[F, H, ?], G]](fa => fa.fold(self, h))
def or[H[_]](h: FunctionK[H, G]): FunctionK[EitherK[F, H, ?], G] =
λ[FunctionK[EitherK[F, H, ?], G]](fa => fa.fold(self, h))

/**
* Composes two instances of `FunctionK` into a new `FunctionK` that transforms
* one single functor to a [[cats.data.Prod]] of two functors.
* one single functor to a [[cats.data.Tuple2K]] of two functors.
*
* {{{
* scala> import cats.arrow.FunctionK
* scala> val list2option = λ[FunctionK[List, Option]](_.headOption)
* scala> val list2vector = λ[FunctionK[List, Vector]](_.toVector)
* scala> val optionAndVector = list2option and list2vector
* scala> optionAndVector(List(1,2,3))
* res0: cats.data.Prod[Option,Vector,Int] = Prod(Some(1),Vector(1, 2, 3))
* res0: cats.data.Tuple2K[Option,Vector,Int] = Tuple2K(Some(1),Vector(1, 2, 3))
* }}}
*/
def and[H[_]](h: FunctionK[F, H]): FunctionK[F, Prod[G, H, ?]] =
λ[FunctionK[F, Prod[G, H, ?]]](fa => Prod(self(fa), h(fa)))
def and[H[_]](h: FunctionK[F, H]): FunctionK[F, Tuple2K[G, H, ?]] =
λ[FunctionK[F, Tuple2K[G, H, ?]]](fa => Tuple2K(self(fa), h(fa)))
}

object FunctionK {
Expand Down
231 changes: 0 additions & 231 deletions core/src/main/scala/cats/data/Coproduct.scala

This file was deleted.

Loading

0 comments on commit 2a32e37

Please sign in to comment.