Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
averymcnab opened this issue Nov 2, 2023 · 0 comments
Open
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@averymcnab
Copy link
Collaborator

averymcnab commented Nov 2, 2023

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)
@averymcnab averymcnab added enhancement New feature or request good first issue Good for newcomers labels Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant