Skip to content

Create a "withField" encoder  #4

@sebsheep

Description

@sebsheep

Hi,

My (weird) json contains either one of 3 possibles fields (say fA, fB and fC). I would like to write a custom coder for this but I'm stucked in the encoder part :

weirdCoder =
    let
        encoder source =
            case source of
                A a -> ??
                    
                B b -> ??

                C c -> ??
   in
      ( encoder
      ,  Decode.oneOf
        [ field "fA" (Decode.map A aDecoder)
        , field "fB" (Decode.map B bDecoder)
        , field "fC" (Decode.map C cDecoder)
        ])

I think it would be easy if the decoders were exposed but there arent...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions