gleam-lang / gleam-lang/stdlib
decode function for keyed varients
- Dominant language
- Gleam
- Stars
- 710
- Forks
- 225
- Avg merge
- 5h 52m
- Merged PRs (30d)
- 3
Description
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
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.