These are chat archives for hseeberger/akka-http-json

25th
Jul 2018
Jens Grassel
@jan0sch
Jul 25 2018 12:22

Hi anyone doing tagless final with akka-http?

We have something like this:

class Service[F[_]: Monad](repo: Repository[F]) {
  def test: Route = path("foo") {
    get {
      complete {
        for {
          so <- repo.loadSession()  // returns an Option[Session]
        } yield so
      }
    }
  }
}

However the compiler complains about a type mismatch:

found   : F[Option[Session]]
required: akka.http.scaladsl.marshalling.ToResponseMarshallable
    so <- repo.loadSession()

Any advise? Do we have to roll our own marshalling?

Olli Helenius
@liff
Jul 25 2018 12:27
@jan0sch you'll have to provide a way to marshal responses from yourF
Jens Grassel
@jan0sch
Jul 25 2018 12:29
But how? ;-)
Olli Helenius
@liff
Jul 25 2018 12:30
something like implicit def fToResponseMarshaller[A: ToResponseMarshaller]: ToResponseMarshaller[F[A]] = ???
i think...
Jens Grassel
@jan0sch
Jul 25 2018 12:30
Okay, so something that abstracts away the F so that the regular marshalling can do its work?
Olli Helenius
@liff
Jul 25 2018 12:31
something like that yeah
the compiler only knows your F is a Monad, so you'll need to also provide some way to marshal things from within your F
Jens Grassel
@jan0sch
Jul 25 2018 12:32
Thanks, I'll try my luck and will report back here if I have something that works. Might be useful for others too.
Olli Helenius
@liff
Jul 25 2018 12:37
i suppose one way to do it could be to provide a FunctionK[F, Future]and build a ToResponseMarshaller from/with that
Jens Grassel
@jan0sch
Jul 25 2018 12:46
Meaning I must provide implementations for all needed types (for example, Future, Task, IO)?
Olli Helenius
@liff
Jul 25 2018 12:51
well at least for whatever F you are using in there
Jens Grassel
@jan0sch
Jul 25 2018 12:51
Okay, thanks.