Module

Foreign.Generic.EnumEncoding

#GenericEnumOptions

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

#defaultGenericEnumOptions

#genericDecodeEnum

genericDecodeEnum :: forall a rep. 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

genericEncodeEnum :: forall a rep. 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

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

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

Modules