Skip to content

Instantly share code, notes, and snippets.

@Swoorup
Created April 29, 2021 11:19
Show Gist options
  • Save Swoorup/6a79270d04caf77a3a185c90d35f6316 to your computer and use it in GitHub Desktop.
Save Swoorup/6a79270d04caf77a3a185c90d35f6316 to your computer and use it in GitHub Desktop.
Scala 3 - Cats effect - Akka Http Marshalling
import akka.http.scaladsl.marshalling.{GenericMarshallers, ToResponseMarshaller}
import cats.Id
import cats.effect.IO
import cats.effect.std.Dispatcher
import cats.syntax.apply.*
import scala.concurrent.Future
object FMarshaller:
given [A](using m: ToResponseMarshaller[A]): ToResponseMarshaller[Future[A]] =
GenericMarshallers.futureMarshaller
given [A](using dispatcher: Dispatcher[IO], m: ToResponseMarshaller[A]): ToResponseMarshaller[IO[A]] =
GenericMarshallers.futureMarshaller(m).compose(dispatcher.unsafeToFuture)
given [A](using m: ToResponseMarshaller[A]): ToResponseMarshaller[Id[A]] = m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment