Open
Description
This is largely a quality-of-life suggestion to make encoder definitions less painful, especially when they have only one or two fields.
Add a def simple()
method on the ContextEncoder
companion object, such as:
def simple[Ctx](_kind: String)(_key: Ctx => String): ContextEncoder[Ctx] = new ContextEncoder[Ctx] {
...
}
Alongside this define methods to allow additional attributes, e.g.
def withStringAttribute(attributeName: String)(f: Ctx => String): ContextEncoder[Ctx] = ...
def withBooleanAttribute(attributeName: String)(f: Ctx => Boolean): ContextEncoder[Ctx] = ...
These can then be used together, for example:
implicit val anEncoder: ContextEncoder[Type] =
ContextEncoder
.simple[Type]("kind")(key = type.someField)
.withStringAttribute("otherKind")(_.someOtherField)