Open ryanprior opened 2 years ago
We can do automatic tuple decoding / encoding, no problem :muscle:
Supporting Map
with any keys is more problematic, we have two options here:
Map(a, b)
would be encoded as [[a, b]]
which is basically its internal representation but with the keys and values encoded. This would be a breaking change because now they are encoded as objects {a: b}
.Map(String, a)
as before so no breaking change since we only allowed String
keys before, but this would mean different behavior with String
keys and the rest.I'm wondering what you folks think :bulb: :thinking:
I'd like encode
on a Map(a, b)
to give a normal JS object if a
is String
, otherwise a JS Map
. This would not work with Mint's Json.stringify
but it could work for other serialization modules that could handle maps with non-string keys, such as if we introduce an EDN module.
You can encode a record, and you can encode a map, but you can't encode a map with record keys. You also can't encode Tuples, which seemed to me like it would be the best workaround.
Here's a sandbox illustrating the issue: https://sandbox.mint-lang.com/sandboxes/Cvi4ReudJVxywQ
Workarounds
I tried to work around this by first transforming the map using
Map.entries
. This didn't work for me because Tuple types also can't be encoded.What did work was ultimately to write my own inline JS like so: