garyb / purescript-codec-argonaut

Bi-directional JSON codecs for argonaut
MIT License
39 stars 16 forks source link

variantMatch function -> don't use either to differentiate between parsers and nullary constructors #28

Open srghma opened 4 years ago

srghma commented 4 years ago

In docs

The fields in the record passed to CAV.variantMatch correspond with the variant constructors. Each one accepts an Either carrying either a codec or a static value - Right with a codec for when there's a value that needs encoding for the constructor, Left with a static value for nullary constructors.

It's better to make it accept

data VariantMatchCodecType a b = Codec a | Nullary b

garyb commented 4 years ago

Why's that? Also, the instructor variable is undefined here, and I'm not sure what the b is for either.

srghma commented 4 years ago

Also, the instructor variable is undefined here

oh, sorry, typo, updated

Why's that?

it's the same as Either, but more descriptive

Codec is better than Left, Nullary is better than Right