Navigation | Overlay |
---|---|
t Navigate files | h Toggle hits |
y Change url to tip of branch | m Toggle misses |
b / v Jump to prev/next hit line | p Toggle partial |
z / x Jump to prev/next missed or partial line | 1..9 Toggle flags |
shift + o Open current page in GitHub | a Toggle all on |
/ or ? Show keyboard shortcuts dialog | c Toggle context lines or commits |
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 |
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 |
implicit val encoderContravariant: Contravariant[Encoder] = new Contravariant[Encoder] { |
|
19 |
def contramap[A, B](fa: Encoder[A])(fn: B => A): Encoder[B] = new Encoder[B] { |
|
20 |
def encode(b: B): Entity = fa.encode(fn(b)) |
|
21 |
}
|
|
22 |
}
|
|
23 |
}
|
|
24 |
|
|
25 |
@typeclass trait Decoder[A] { |
|
26 |
def decode(a: Entity): Either[CodecException, A] |
|
27 |
}
|
|
28 |
|
|
29 |
@typeclass trait Codec[A] extends Encoder[A] with Decoder[A] |
Read our documentation on viewing source code .