Skip to content

Commit

Permalink
Rename FreeT.inject to FreeT.liftInject (typelevel#1534)
Browse files Browse the repository at this point in the history
  • Loading branch information
valydia committed Mar 7, 2018
1 parent ee34154 commit cc5a989
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
14 changes: 7 additions & 7 deletions free/src/main/scala/cats/free/FreeT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,19 @@ object FreeT extends FreeTInstances {
/**
* This method is used to defer the application of an InjectK[F, G]
* instance. The actual work happens in
* `FreeTInjectKPartiallyApplied#apply`.
* `FreeTLiftInjectKPartiallyApplied#apply`.
*
* This method exists to allow the `F`, `M` and `G` parameters to be
* bound independently of the `A` parameter below.
* This method exists to allow the `M` and `G` parameters to be
* bound independently of the `F` and `A` parameters below.
*/
def inject[F[_], M[_], G[_]]: FreeTInjectKPartiallyApplied[F, M, G] =
new FreeTInjectKPartiallyApplied
def liftInject[M[_], G[_]]: FreeTLiftInjectKPartiallyApplied[M, G] =
new FreeTLiftInjectKPartiallyApplied

/**
* Uses the [[http://typelevel.org/cats/guidelines.html#partially-applied-type-params Partially Applied Type Params technique]] for ergonomics.
*/
private[free] final class FreeTInjectKPartiallyApplied[F[_], M[_], G[_]](val dummy: Boolean = true ) extends AnyVal {
def apply[A](fa: F[A])(implicit I: InjectK[F, G], m: Applicative[M]): FreeT[G, M, A] =
private[free] final class FreeTLiftInjectKPartiallyApplied[M[_], G[_]](val dummy: Boolean = true ) extends AnyVal {
def apply[F[_], A](fa: F[A])(implicit I: InjectK[F, G], m: Applicative[M]): FreeT[G, M, A] =
FreeT.liftF[G, M, A](I.inj(fa))
}
}
Expand Down
10 changes: 7 additions & 3 deletions free/src/test/scala/cats/free/FreeTSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ class FreeTSuite extends CatsSuite {

case class Test1[A](value : Int, f: Int => A) extends Test1Algebra[A]

def test1[A](value: Int, f: Int => A): Test1Algebra[A] = Test1(value, f)

object Test1Algebra {
implicit def test1AlgebraAFunctor: Functor[Test1Algebra] =
new Functor[Test1Algebra] {
Expand All @@ -136,6 +138,8 @@ class FreeTSuite extends CatsSuite {

case class Test2[A](value : Int, f: Int => A) extends Test2Algebra[A]

def test2[A](value: Int, f: Int => A): Test2Algebra[A] = Test2(value, f)

object Test2Algebra {
implicit def test2AlgebraAFunctor: Functor[Test2Algebra] =
new Functor[Test2Algebra] {
Expand Down Expand Up @@ -164,14 +168,14 @@ class FreeTSuite extends CatsSuite {

val eitherKInterpreter: FunctionK[T,Id] = Test1Interpreter or Test2Interpreter

test(".inject") {
test(".liftInject") {
forAll { (x: Int, y: Int) =>
def res[F[_]]
(implicit I0: Test1Algebra :<: F,
I1: Test2Algebra :<: F): FreeT[F, Id, Int] = {
for {
a <- FreeT.inject[Test1Algebra, Id, F](Test1(x, identity))
b <- FreeT.inject[Test2Algebra, Id, F](Test2(y, identity))
a <- FreeT.liftInject[Id, F](test1(x, identity))
b <- FreeT.liftInject[Id, F](test2(y, identity))
} yield a + b
}
(res[T] foldMap eitherKInterpreter) == (x + y) should ===(true)
Expand Down

0 comments on commit cc5a989

Please sign in to comment.