Module

Foreign.Generic.EnumEncoding

Package
purescript-foreign-generic
Repository
paf31/purescript-foreign-generic

#GenericEnumOptions Source

type GenericEnumOptions = { constructorTagTransform :: String -> String }

#genericDecodeEnum Source

genericDecodeEnum :: forall rep a. Generic a rep => GenericDecodeEnum rep => GenericEnumOptions -> Foreign -> F a

A generic function to be used with "Enums", or sum types with only no-argument constructors. This is used for decoding from strings to one of the constructors, combined with the constructorTagTransform property of SumEncoding.

#genericEncodeEnum Source

genericEncodeEnum :: forall rep a. Generic a rep => GenericEncodeEnum rep => GenericEnumOptions -> a -> Foreign

A generic function to be used with "Enums", or sum types with only no-argument constructors. This is used for encoding to strings from one of the constructors, combined with the constructorTagTransform property of SumEncoding.

For example:

data Fruit = Apple | Banana | Frikandel
derive instance geFruit :: Generic Fruit _
instance eFruit :: Encode Fruit where
  encode = genericEncodeEnum defaultGenericEnumOptions

#GenericDecodeEnum Source

class GenericDecodeEnum a  where

A type class for type representations that can be used for decoding to an Enum. Only the sum and no-argument constructor instances are valid, while others provide a Fail constraint to fail in compilation.

For example:

data Fruit = Apple | Banana | Frikandel
derive instance geFruit :: Generic Fruit _
instance dFruit :: Decode Fruit where
  decode = genericDecodeEnum defaultGenericEnumOptions

Members

Instances

#GenericEncodeEnum Source

class GenericEncodeEnum a  where

A type class for type representations that can be used for encoding from an Enum. Only the sum and no-argument constructor instances are valid, while others provide a Fail constraint to fail in compilation.

Members

Instances