Data.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
decodeEnum :: GenericEnumOptions -> Foreign -> F a
Instances
(GenericDecodeEnum a, GenericDecodeEnum b) => GenericDecodeEnum (Sum a b)
(IsSymbol name) => GenericDecodeEnum (Constructor name NoArguments)
(Fail "genericEncode/DecodeEnum cannot be used on types that are not sums of constructors with no arguments.") => GenericDecodeEnum (Constructor name (Argument a))
(Fail "genericEncode/DecodeEnum cannot be used on types that are not sums of constructors with no arguments.") => GenericDecodeEnum (Constructor name (Product a b))
(Fail "genericEncode/DecodeEnum cannot be used on types that are not sums of constructors with no arguments.") => GenericDecodeEnum (Constructor name (Rec a))
#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
encodeEnum :: GenericEnumOptions -> a -> Foreign
Instances
(GenericEncodeEnum a, GenericEncodeEnum b) => GenericEncodeEnum (Sum a b)
(IsSymbol name) => GenericEncodeEnum (Constructor name NoArguments)
(Fail "genericEncode/DecodeEnum cannot be used on types that are not sums of constructors with no arguments.") => GenericEncodeEnum (Constructor name (Argument a))
(Fail "genericEncode/DecodeEnum cannot be used on types that are not sums of constructors with no arguments.") => GenericEncodeEnum (Constructor name (Product a b))
(Fail "genericEncode/DecodeEnum cannot be used on types that are not sums of constructors with no arguments.") => GenericEncodeEnum (Constructor name (Rec a))