Module

Data.Codec.Argonaut.Generic

#nullarySum

nullarySum :: forall a r. Generic a r => NullarySumCodec r => String -> JsonCodec a

Encodes nullary sums with a Generic instance as strings that match the constructor names.

import Data.Argonaut as J

data MySum = Ctor1 | Ctor2 | MoarCtors
derive instance genericMySum ∷ Generic MySum _

encode (nullarySum "MySum") Ctor1 == J.fromString "Ctor1"
decode (nullarySum "MySum") (J.fromString "MoarCtors") == Right MoarCtors

Modules