elm-community / json-extra

Convenience functions for working with Json.
http://package.elm-lang.org/packages/elm-community/json-extra/latest
MIT License
37 stars 16 forks source link

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

Open Herteby opened 5 years ago

Herteby commented 5 years ago

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

lydell commented 4 years ago

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

Herteby commented 4 years ago

@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 ?