Skip to content

Commit

Permalink
Merge pull request #524 from adelbertc/freeapplicative-remove-hoist
Browse files Browse the repository at this point in the history
FreeApplicative#hoist is same as compile
  • Loading branch information
non committed Sep 13, 2015
2 parents b92c3eb + 6df3cdc commit 7be80e5
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions free/src/main/scala/cats/free/FreeApplicative.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ sealed abstract class FreeApplicative[F[_], A] extends Product with Serializable
case x@Ap() => apply(x.pivot)(x.fn.map(f compose _))
}

/** Natural Transformation of FreeApplicative based on given Natural Transformation */
final def hoist[G[_]](f: F ~> G): FA[G, A] =
this match {
case Pure(a) => Pure[G, A](a)
case x@Ap() => apply(f(x.pivot))(x.fn.hoist(f))
}

/** Interprets/Runs the sequence of operations using the semantics of Applicative G
* Tail recursive only if G provides tail recursive interpretation (ie G is FreeMonad)
*/
Expand All @@ -45,7 +38,8 @@ sealed abstract class FreeApplicative[F[_], A] extends Product with Serializable
final def fold(implicit F: Applicative[F]): F[A] =
foldMap(NaturalTransformation.id[F])

final def compile[G[_]](f: F ~> G)(implicit G: Applicative[G]): FA[G, A] =
/** Interpret this algebra into another FreeApplicative */
final def compile[G[_]](f: F ~> G): FA[G, A] =
foldMap[FA[G, ?]] {
new NaturalTransformation[F, FA[G, ?]] {
def apply[B](fa: F[B]): FA[G, B] = lift(f(fa))
Expand Down

0 comments on commit 7be80e5

Please sign in to comment.