purescript-foreign-generic
purescript-foreign-generic copied to clipboard
De/Encode instance for Data.Map
I'm wondering what the preferred way of writing a de/encode instance for Data.Map
would be?
I have an initial implementation in a fork here ( https://github.com/rubenpieters/purescript-foreign-generic/commit/e2f24edce0ce819978e4c3d343df846e147d3fe6 ).
Some choices I made:
- Convert the
Data.Map
from/to aData.StrMap
, then encode/decode it similarly toData.StrMap
's instance - All keys are first converted to
String
s, so I introduced anEncodeKey
/DecodeKey
class which can encode or decode keys to/fromString
respectively
Also in the initial implementation only the first decoding error is reported, I think the current StrMap
doesn't report all decoding errors either. But that can definitely be fixed.
There are a lot of possibilities, so maybe it would be interesting to discuss the preferred way of doing it first.
The referenced instance for StrMap
: https://github.com/paf31/purescript-foreign-generic/pull/28
Earlier attempt at instance for Map
: https://github.com/paf31/purescript-foreign-generic/pull/29
It appears the instance for StrMap
was replaced with an instance for Object
(https://pursuit.purescript.org/packages/purescript-foreign-object/2.0.3/docs/Foreign.Object#t:Object): https://github.com/paf31/purescript-foreign-generic/commit/54b26dc84b07d851a83cad0fd2d477c4b8045786#diff-71732b478b4808898d86c8591ad7ab46d8122c1e4facec4a9151ac49efba905dR105
Perhaps there should be instances for https://github.com/purescript/purescript-ordered-collections (Data.Map
, as you've said?)