purescript-contrib / purescript-argonaut-codecs

JSON serialization and deserialization with Argonaut.
MIT License
48 stars 46 forks source link

Beginner-friendly syntax in decodeJsonTuple #76

Closed milesfrain closed 4 years ago

milesfrain commented 4 years ago

This is just different syntax that's functionally equivalent. It is covered by, and passes, existing quickCheck tests.

Motivation for this change is that I'm planning on pointing readers of Ch10 (rewrite targeting argonaut in-progress) to decodeJsonTuple for guidance on writing their own DecodeJson instances in one of the exercises, and I'd like this library example to be as easy as possible for beginners to grok.

This is an extension of #75.

thomashoneyman commented 4 years ago

Thanks!

garyb commented 4 years ago

I actually think lift2 is way weirder (in an idiomatic sense at least) than the f <$> x <*> y pattern. I've never used lift2, and very rarely see it used.

milesfrain commented 4 years ago

I'm not opposed to reverting that component of this change.

The lift# functions get some decent coverage in the book. If we don't consider that an idiomatic way to write PS, then I think we should eliminate that section.

I'm wondering if the same should be said of ado notation, which was another option in place of lift2.

thomashoneyman commented 4 years ago

I'm happy with whatever for the implementation -- I just found it odd that tuples encode via arrays and decode via lists, and would prefer it to encode / decode to the same type.

Edit: Re-reading the PR description, I also don't think this code specifically (meaning a link to this code) should be used in the PureScript book, but rather that the book should probably just inline whatever code style it wants to use. That said, I'm still happy to change to use arrays in both encoding / decoding and the difference between lift2 and >>= isn't that big to me.