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

FreeApplicative#hoist is same as compile #524

Merged
merged 3 commits into from
Sep 13, 2015
Merged
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
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