Skip to content
This repository has been archived by the owner on Nov 25, 2021. It is now read-only.

Commit

Permalink
make marshallable instance generic
Browse files Browse the repository at this point in the history
  • Loading branch information
poohsen authored and poohsen committed Feb 24, 2021
1 parent 09ff055 commit 7dc7fba
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.thenewmotion.ocpi.common

import akka.http.scaladsl.marshalling.{GenericMarshallers, ToRequestMarshaller, ToResponseMarshaller}
import cats.effect.{ContextShift, IO}
import cats.effect.{ContextShift, Effect}
import scala.concurrent.Future

/**
Expand All @@ -22,12 +22,12 @@ object HktMarshallableInstances {
def requestMarshaller[A : ToRequestMarshaller]: ToRequestMarshaller[Future[A]] = implicitly
}

implicit def ioMarshaller(implicit s: ContextShift[IO]): HktMarshallable[IO] = new HktMarshallable[IO] {
def responseMarshaller[A](implicit m: ToResponseMarshaller[A]): ToResponseMarshaller[IO[A]] =
GenericMarshallers.futureMarshaller(m).compose(io => (s.shift *> io).unsafeToFuture())
implicit def effectMarshaller[F[_]: Effect](implicit s: ContextShift[F], eff: Effect[F]): HktMarshallable[F] = new HktMarshallable[F] {
def responseMarshaller[A](implicit m: ToResponseMarshaller[A]): ToResponseMarshaller[F[A]] =
GenericMarshallers.futureMarshaller(m).compose(io => eff.toIO(eff.flatMap(s.shift)(_ => io)).unsafeToFuture())

def requestMarshaller[A](implicit m: ToRequestMarshaller[A]): ToRequestMarshaller[IO[A]] =
GenericMarshallers.futureMarshaller(m).compose(io => (s.shift *> io).unsafeToFuture())
def requestMarshaller[A](implicit m: ToRequestMarshaller[A]): ToRequestMarshaller[F[A]] =
GenericMarshallers.futureMarshaller(m).compose(io => eff.toIO(eff.flatMap(s.shift)(_ => io)).unsafeToFuture())
}
}

Expand Down

0 comments on commit 7dc7fba

Please sign in to comment.