-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Belt.Map.t #5
Comments
Yes, please add this. It's a pretty basic piece of functionality. Here's how I'm working around it right now for
The |
Same idea, applied to integers. let intMapToJson = (encode: 'a => Js.Json.t, map: Belt.Map.Int.t('a)) =>
Json.Encode.object_(
Belt.List.map(Belt.Map.Int.toList(map), ((key, item)) =>
(string_of_int(key), encode(item))
),
);
let deccoIntMapFromJson = (decode, json) => {
switch (Decco.dictFromJson(decode, json)) {
| Belt.Result.Ok(result) =>
Ok(Js.Dict.entries(result)
-> Belt.Array.map(((key, value)) => (int_of_string(key), value))
-> Belt.Map.Int.fromArray)
| Belt.Result.Error(error) => Error(error)
};
};
[@decco]
type intMap('a) =
[@decco.codec (intMapToJson, deccoIntMapFromJson)] Belt.Map.Int.t('a); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No description provided.
The text was updated successfully, but these errors were encountered: