From 071dcdb9a71ab41730c9467fdb11ab60080e43f4 Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Tue, 24 Jan 2017 10:44:54 -0800 Subject: [PATCH 1/3] inj --- free/src/main/scala/cats/free/Free.scala | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/free/src/main/scala/cats/free/Free.scala b/free/src/main/scala/cats/free/Free.scala index 336e27d6ff..5257c0fa36 100644 --- a/free/src/main/scala/cats/free/Free.scala +++ b/free/src/main/scala/cats/free/Free.scala @@ -141,6 +141,13 @@ sealed abstract class Free[S[_], A] extends Product with Serializable { } }(Free.catsFreeMonadForFree) + /** + * Lift into `G` (typically a `Coproduct`) given `Inject`. Analogous + * to `Free.inject` but lifts programs rather than constructors. + */ + final def inject[G[_]](implicit ev: Inject[F, G]): Free[G, A] = + compile(λ[F ~> G](ev.inj(_))) + override def toString: String = "Free(...)" } From 81ba2800f2f0d4d0f5a17b15debd9c4737c0865a Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Tue, 24 Jan 2017 11:17:29 -0800 Subject: [PATCH 2/3] doh --- free/src/main/scala/cats/free/Free.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/free/src/main/scala/cats/free/Free.scala b/free/src/main/scala/cats/free/Free.scala index 5257c0fa36..bcd38cd01e 100644 --- a/free/src/main/scala/cats/free/Free.scala +++ b/free/src/main/scala/cats/free/Free.scala @@ -145,8 +145,8 @@ sealed abstract class Free[S[_], A] extends Product with Serializable { * Lift into `G` (typically a `Coproduct`) given `Inject`. Analogous * to `Free.inject` but lifts programs rather than constructors. */ - final def inject[G[_]](implicit ev: Inject[F, G]): Free[G, A] = - compile(λ[F ~> G](ev.inj(_))) + final def inject[G[_]](implicit ev: Inject[S, G]): Free[G, A] = + compile(λ[S ~> G](ev.inj(_))) override def toString: String = "Free(...)" From 40041dd1c9abc29e8cdbbbee794a877102451e84 Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Tue, 24 Jan 2017 12:53:39 -0800 Subject: [PATCH 3/3] doctest --- free/src/main/scala/cats/free/Free.scala | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/free/src/main/scala/cats/free/Free.scala b/free/src/main/scala/cats/free/Free.scala index bcd38cd01e..b7a083610b 100644 --- a/free/src/main/scala/cats/free/Free.scala +++ b/free/src/main/scala/cats/free/Free.scala @@ -144,6 +144,17 @@ sealed abstract class Free[S[_], A] extends Product with Serializable { /** * Lift into `G` (typically a `Coproduct`) given `Inject`. Analogous * to `Free.inject` but lifts programs rather than constructors. + * + *{{{ + *scala> type Lo[A] = cats.data.Coproduct[List, Option, A] + *defined type alias Lo + * + *scala> val fo = Free.liftF(Option("foo")) + *fo: cats.free.Free[Option,String] = Free(...) + * + *scala> fo.inject[Lo] + *res4: cats.free.Free[Lo,String] = Free(...) + *}}} */ final def inject[G[_]](implicit ev: Inject[S, G]): Free[G, A] = compile(λ[S ~> G](ev.inj(_)))