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

Service composition syntax with <+> doesn't work for AuthedService #1506

Closed
SystemFw opened this issue Oct 30, 2017 · 0 comments · Fixed by #1509
Closed

Service composition syntax with <+> doesn't work for AuthedService #1506

SystemFw opened this issue Oct 30, 2017 · 0 comments · Fixed by #1509

Comments

@SystemFw
Copy link
Member

Some people have already stumbled upon this in the wild: <+> syntax doesn't work for AuthedService (also referenced in #1501).

The issue boils down to

 type AuthedService[F[_], T] = Kleisli[OptionT[F, ?], AuthedRequest[F, T], Response[F]]

having T on the right, which prevents partial unification from triggering.

Minimisation:

object Gotcha {
  import cats._, data._, implicits._

  implicit def http4sKleisliSemigroupK[F[_]: SemigroupK, A]: SemigroupK[Kleisli[F, A, ?]] =
    new SemigroupK[Kleisli[F, A, ?]] {
      def combineK[B](x: Kleisli[F, A, B], y: Kleisli[F, A, B]) =
        Kleisli(req => x(req) <+> y(req))
    }

  case class Req[F[_]]()
  case class Res[F[_]]()

  type Service[F[_]] = Kleisli[OptionT[F, ?], Req[F], Res[F]]

  def normal[F[_]: Monad](a: Service[F], b: Service[F]) = a <+> b

  case class AuthedReq[F[_], T]()
  type AuthedService[F[_], T] = Kleisli[OptionT[F, ?], AuthedReq[F, T], Res[F]]
  type AuthedServiceSwapped[T, F[_]] = Kleisli[OptionT[F, ?], AuthedReq[F, T], Res[F]]

  // def doesNotCompile[F[_]: Monad, T](a: AuthedService[F, T], b: AuthedService[F, T]) =
  //   a <+> b

  def compiles[F[_]: Monad, T](a: AuthedServiceSwapped[T, F], b: AuthedServiceSwapped[T, F]) =
    a <+> b
}

I'll PR a fix for this asap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant