Skip to content

Create a typeclass for custom decoding #30

@zainab-ali

Description

@zainab-ali

The server contains a decoder trait to decode our custom format into algebraic data types. This can be modelled as a typeclass with instances for each datatype.

We can then make use of several libraries to help construct and use the decoder. simulacrum can be used to generate ops, and magnolia for typeclass derivation.

Potential Solution

Enrich lsug.markup.Decoder trait with ops using simulacrum. This makes working with decoders a little easier.
You can then write the functions required for magnolia to derive instances automatically.
The current decoders are explicit in lsug.markup.Decoders. These can be made implicit and, where possible, rewritten to be derived automatically.

Note that most of the decoders probably won't be able to use generic derivation as they have custom handling for missing tags.

Tests

The assertions in lsug.markup.DecoderAssertions should be rewritten to use an implicit decoder. The existing tests should cover the rewrite, but feel free to add more.

Prerequisites

You should

  • have a basic understanding of functional programming
  • be comfortable using typeclasses on higher-kinded types, for example Functor.
  • be keen on reducing boilerplate

What you'll learn

  • How to create typeclasses with implicits and ops
  • How to use simulacrum to generate typeclass boilerplate
  • How to use magnolia to generate typeclass instances

Getting started

Read our Contributor Guide to get set up.

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