1
package hammock
2

3
import cats._
4
import simulacrum.typeclass
5

6
class CodecException private (val message: String, underlying: Throwable) extends Throwable(message, underlying)
7

8
object CodecException {
9 0
  def withMessage(message: String)                            = new CodecException(message, null)
10 1
  def withMessageAndException(message: String, ex: Throwable) = new CodecException(message, ex)
11
}
12

13 1
@typeclass trait Encoder[A] {
14
  def encode(a: A): Entity
15
}
16

17
object Encoder {
18 0
  implicit val encoderContravariant: Contravariant[Encoder] = new Contravariant[Encoder] {
19 0
    def contramap[A, B](fa: Encoder[A])(fn: B => A): Encoder[B] = new Encoder[B] {
20 0
      def encode(b: B): Entity = fa.encode(fn(b))
21
    }
22
  }
23
}
24

25 0
@typeclass trait Decoder[A] {
26
  def decode(a: Entity): Either[CodecException, A]
27
}
28

29 0
@typeclass trait Codec[A] extends Encoder[A] with Decoder[A]

Read our documentation on viewing source code .

Loading