Skip to content

Encode.dict & Decode.dict are asymmetrical #17

Description

Hello!

I'm working with dictionaries of character-based keys. Encoding them is straight-forward, as I simply have to convert keys from characters to strings. No problem!

Writing the decoder for this kind of dictionary was more problematic, as I don't have the option convert keys back into characters.

Encode.dict : (k -> String) -> (v -> Encode.Value) -> Dict k v -> Encode.Value

Decode.dict : Decoder a -> Decoder (Dict String a)

I am working around this, but I'd love for the solution to be incorporated into Decode.dict, to avoid the additional passes through the data.

Proposed solution

I'd really like these functions to be symmetrical, in the sense that the dictionary-decoder takes a function to convert the string-key into a comparable value in the same way the encoder requires me to convert the comparable keys into strings.

Perhaps like this:

Decode.dict : (String -> comparable) -> Decoder a -> Decoder (Dict comparable a)

To spare you the time, I could do this implementation for you, but let me know what you think when you have the time ☀️

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions