roc icon indicating copy to clipboard operation
roc copied to clipboard

Derive decoders for tag unions

Open rtfeldman opened this issue 3 years ago • 1 comments

  • [ ] Add discriminant : List (List U8) -> Decoder Nat fmt | fmt has DecoderFormatting to DecoderFormatting and update Json.roc to implement it.
  • [ ] Derive decoders for tags based on that.

rtfeldman avatar Aug 15 '22 21:08 rtfeldman

I think we may need to add

## [sequence state stepElem finalizer] decodes a possibly-heterogenous sequence representation into `state`.
sequence : state, (state -> [Keep (Decoder state fmt), Skip]), (state -> Result val DecodeError) -> Decoder val fmt | fmt has DecoderFormatting

which parses a heterogenous list (like that of a tag's payload) in order to support multi-payload tags. There is an example at https://www.notion.so/rwx/Roc-s-Decoding-API-6a9cd9b5c5ec4602b796e8b5a8857697

ayazhafiz avatar Aug 15 '22 23:08 ayazhafiz