purescript-foreign-generic icon indicating copy to clipboard operation
purescript-foreign-generic copied to clipboard

De/Encode instance for Data.Map

Open rubenpieters opened this issue 7 years ago • 2 comments

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 a Data.StrMap, then encode/decode it similarly to Data.StrMap's instance
  • All keys are first converted to Strings, so I introduced an EncodeKey/DecodeKey class which can encode or decode keys to/from String 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.

rubenpieters avatar Dec 05 '17 12:12 rubenpieters

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

peterbecich avatar Feb 22 '21 04:02 peterbecich

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

peterbecich avatar Feb 22 '21 04:02 peterbecich