
hammock.marshalling.scala Maven / Gradle / Ivy
The newest version!
package hammock
import cats._
import cats.free._
import cats.effect.Sync
object marshalling {
sealed trait MarshallF[A] {
def dec: Decoder[A] //
}
object MarshallF {
def unmarshall[A: Decoder](entity: Entity): MarshallF[A] =
Unmarshall(entity)
private[marshalling] final case class Unmarshall[A](entity: Entity)(implicit D: Decoder[A]) extends MarshallF[A] {
def dec = D
}
}
object Ops {
def unmarshall[A: Decoder](entity: Entity): Free[MarshallF, A] =
Free.liftF(MarshallF.unmarshall(entity))
}
class MarshallC[F[_]](implicit I: MarshallF :<: F) {
def unmarshall[A: Decoder](entity: Entity): Free[F, A] =
Ops.unmarshall(entity).inject
}
implicit def marshallC[F[_]](implicit I: InjectK[MarshallF, F]): MarshallC[F] = new MarshallC[F]
implicit def marshallNT[F[_]: Sync]: MarshallF ~> F = λ[MarshallF ~> F] {
case [email protected](entity) => um.dec
.decode(entity)
.fold(Sync[F].raiseError, Sync[F].pure)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy