json-extra icon indicating copy to clipboard operation
json-extra copied to clipboard

Decoder k -> Decoder v -> Decoder (List ( k, v ))

Open Herteby opened this issue 6 years ago • 2 comments

Would be nice to have a key-value decoder that allowed you to specify the key decoder, instead of it always being String :slightly_smiling_face:

Useful when using wrapped types like type ID = ID String

Herteby avatar May 17 '19 10:05 Herteby

Like dict2, but keyValuePairs2?

If so, wouldn’t (String -> Decoder k) -> Decoder v -> Decoder (List ( k, v )) make more sense? I’m thinking it is strange to ask for a decoder for the keys when we know that only Json.Decode.string would ever succeed (since object keys are always strings). See also: https://github.com/elm-community/json-extra/issues/22#issuecomment-544285606

lydell avatar Oct 20 '19 19:10 lydell

@lydell True, String -> Decoder k would work, although it looks a bit odd I think. How about String -> Maybe k or String -> Result String k ?

Herteby avatar Nov 08 '19 13:11 Herteby