Module
Data.Codec.Argonaut.Generic
- Package
- purescript-codec-argonaut
- Repository
- garyb/purescript-codec-argonaut
#nullarySum Source
nullarySum :: forall r a. 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
#NullarySumCodec Source
class NullarySumCodec r where
Members
nullarySumEncode :: r -> Json
nullarySumDecode :: String -> Json -> Either JsonDecodeError r
Instances
(NullarySumCodec a, NullarySumCodec b) => NullarySumCodec (Sum a b)
(IsSymbol name) => NullarySumCodec (Constructor name NoArguments)