Created
May 8, 2019 12:15
-
-
Save danslapman/dd7a8742817159d818697738b136e646 to your computer and use it in GitHub Desktop.
Encoding enumeratum enums with morphling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class TEnum[P[_], R, A](repr: P[R], ve: ValueEnum[R, A])(implicit val ev: A <:< ValueEnumEntry[R]) extends TType[P, A] | |
.. | |
def tEnum[I, E](repr: Schema[TSchema, I], ve: ValueEnum[I, E])(implicit ev: E <:< ValueEnumEntry[I]): Schema[TSchema, E] = | |
prim(HMutu(TEnum(repr, ve))) | |
.. | |
override val encoder: TSchema ~> Encoder = new (TSchema ~> Encoder) { | |
override def apply[A](ts: TSchema[A]): Encoder[A] = ts.unmutu match { | |
... | |
case te: TEnum[Schema[TSchema, ?], r, A] => | |
te.repr.encoder.contramap[A](a => te.ev(a).value) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment