Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Data.Ron.Class.Deriving
Contents
Description
Allows deriving ron encoding-decoding instances with DerivingVia
. See RonWith
Synopsis
- newtype RonWith s a = RonWith a
- data UseStrict
- data EncodeWith a
- data DecodeWith a
- data ConvertWith a
- data FieldsToSnakeCase
- data FieldsDropPrefix
- data ImplicitSome
- data NoImplicitSome
- data SkipSingleConstructor
- data NoSkipSingleConstructor
- class ReflectSettingsOptions a where
- reflectS :: Proxy a -> RonSettings -> RonSettings
- class ReflectFlagOptions a where
Documentation
Helper for deriving Ron instances. Use like this:
data MyType = MyType {...} deriving (Eq, Show, Generic) deriving (ToRon, FromRon) via RonWith '[FieldsDropPrefix, EncodeWith SkipSingleConstructor] MyType
This is identical to
data MyType = MyType {...} deriving (Eq, Show, Generic) instance ToRon MyType where toRon = let settings = (s{encodeFlags} -> s{encodeFlags = encodeFlags{skipSingleConstructor = True}}) . (s{fieldModifier} -> s{dropPrefix . fieldModifier}) $ laxRonSettings in toRonGeneric settings
The options are applied left to right, and the starting options are
laxRonSettings
All of built-in settings are documented in Deriving
module.
You can define your own settings by creating new datatypes and creating
instances for ReflectSettingsOptions
or ReflectFlagOptions
Constructors
RonWith a |
Settings
Replace the current settings with strictRonSettings
Instances
ReflectSettingsOptions UseStrict Source # | |
Defined in Data.Ron.Class.Deriving Methods reflectS :: Proxy UseStrict -> RonSettings -> RonSettings Source # |
data EncodeWith a Source #
Sets a flag in encodeFlags
. Can set anything with ReflectFlagOptions
instances, like ImplicitSome
, SkipSingleConstructor
Instances
ReflectFlagOptions a => ReflectSettingsOptions (EncodeWith a :: Type) Source # | |
Defined in Data.Ron.Class.Deriving Methods reflectS :: Proxy (EncodeWith a) -> RonSettings -> RonSettings Source # |
data DecodeWith a Source #
Sets a flag in decodeFlags
. Can set anything with ReflectFlagOptions
instances
Instances
ReflectFlagOptions a => ReflectSettingsOptions (DecodeWith a :: Type) Source # | |
Defined in Data.Ron.Class.Deriving Methods reflectS :: Proxy (DecodeWith a) -> RonSettings -> RonSettings Source # |
data ConvertWith a Source #
Same as setting both EncodeWith
and DecodeWith
Instances
ReflectFlagOptions a => ReflectSettingsOptions (ConvertWith a :: Type) Source # | |
Defined in Data.Ron.Class.Deriving Methods reflectS :: Proxy (ConvertWith a) -> RonSettings -> RonSettings Source # |
data FieldsToSnakeCase Source #
Convert fields to snake case. If your field also has prefix, you want to
have this option after FieldsDropPrefix
, as options are applied left to
right
Instances
ReflectSettingsOptions FieldsToSnakeCase Source # | |
Defined in Data.Ron.Class.Deriving Methods reflectS :: Proxy FieldsToSnakeCase -> RonSettings -> RonSettings Source # |
data FieldsDropPrefix Source #
Drop the prefix that is usually used with lenses, that is an underscore
followed by several lowercase letters; regex for this prefix is
s/^_[[:lowercase:]]+([[:uppercase:]].*)/\1/
. You probably want to use
this field modifier before other field modifiers, as they are applied left
to right
Instances
ReflectSettingsOptions FieldsDropPrefix Source # | |
Defined in Data.Ron.Class.Deriving Methods reflectS :: Proxy FieldsDropPrefix -> RonSettings -> RonSettings Source # |
data ImplicitSome Source #
Encode or decode flag that sets implicitSome
to True
Instances
ReflectFlagOptions ImplicitSome Source # | |
Defined in Data.Ron.Class.Deriving |
data NoImplicitSome Source #
Encode or decode flag that sets implicitSome
to False
Instances
data SkipSingleConstructor Source #
Encode or decode flag that sets skipSingleConstructor
to True
Instances
data NoSkipSingleConstructor Source #
Encode or decode flag that sets skipSingleConstructor
to False
Instances
Undelying typeclasses
class ReflectSettingsOptions a where Source #
Typeclass for you to implement your own options. Here's how
FieldsToSnakeCase
uses it:
instance ReflectSettingsOptions FieldsToSnakeCase where reflectS Proxy s@RonSettings {fieldModifier} = s { fieldModifier = toSnake . fieldModifier }
Be careful when composing functions to apply them after the already present, to preserve the left-to-right semantics of adding the options
Methods
reflectS :: Proxy a -> RonSettings -> RonSettings Source #
Instances
class ReflectFlagOptions a where Source #
Typeclass for you to implement your own symmetric options. Here's how
ImplicitSome
uses it
instance ReflectFlagOptions ImplicitSome where reflectF Proxy flags = flags { implicitSome = True }