Skip to content

Add a simple ContextEncoder for quick definitions of simple encoders #93

Description

@averymcnab

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions