diff --git a/free/src/main/scala/cats/free/FreeApplicative.scala b/free/src/main/scala/cats/free/FreeApplicative.scala index b147fab310..710f44dff3 100644 --- a/free/src/main/scala/cats/free/FreeApplicative.scala +++ b/free/src/main/scala/cats/free/FreeApplicative.scala @@ -155,12 +155,12 @@ object FreeApplicative { // Internal helper function for foldMap, it folds only Pure and Lift nodes private[free] def foldArg[F[_], G[_], A](node: FA[F, A], f: F ~> G)(implicit G: Applicative[G]): G[A] = { - node match { - case Pure(x) => - G.pure(x) - case Lift(fa) => - f(fa) - case _ => sys.error("\"impossible\", foldArg should be called on Pure or Lift nodes only") + if (node.isInstanceOf[Pure[F, A]]) { + val Pure(x) = node + G.pure(x) + } else { + val Lift(fa) = node + f(fa) } }