Skip to content

decode function for keyed varients #843

@CrowdHailer

Description

@CrowdHailer

I think with the current API the expected way to solve varients is using one_of this doesn't give very good errors.
I have been using the following function in several projects. It decodes first a discriminator then picks a subsequent decoder based on it.
This allows it to show a specific error for the discriminator, and then good errors if the discriminator is known but it still fails to decode.

Here is the function https://github.com/CrowdHailer/oas/blob/main/src/oas/decodex.gleam#L3

Check the tests for using it and the errors it gives https://github.com/CrowdHailer/oas/blob/main/test/oas/decodex_test.gleam

I'm sure there's an argument for not extending the standard library, in which case I'd be interested in the best way to define a decoder (just a decoder without an essentially similar discriminate function extracted) that gives useful errors.

The proposal in this issue is to add a discriminate function the same or similar to the one I have linked here

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions