Toml.Schema.Generic.ToValue

toml-parser-2.0.1.0: TOML 1.0.0 parser

Copyright | (c) Eric Mertens 2023
License | ISC
Maintainer | emertens@gmail.com
Safe Haskell | None
Language | Haskell2010

Toml.Schema.Generic.ToValue

Contents

- Records to Tables
- Product types to Arrays

Description

Use `genericToTable` to derive an instance of `ToTable` using the field names of a record.

Use `genericToArray` to derive an instance of `ToValue` using the positions of data in a constructor.

Synopsis

- class GToTable (f :: Type -> Type) where
  - gToTable :: f a -> [(Text, Value)] -> [(Text, Value)]
- genericToTable :: (Generic a, GToTable (Rep a)) => a -> Table
- class GToArray (f :: Type -> Type) where
  - gToArray :: f a -> [Value] -> [Value]
- genericToArray :: (Generic a, GToArray (Rep a)) => a -> Value

# Records to Tables

class GToTable (f :: Type -> Type) where #

Supports conversion of product types with field selector names to TOML values.

Methods

gToTable :: f a -> [(Text, Value)] -> [(Text, Value)] #

#### Instances

Instances details

GToTable (U1 :: Type -> Type) # | Emits empty table
Instance details Defined in Toml.Schema.Generic.ToValue Methods gToTable :: U1 a -> [(Text, Value)] -> [(Text, Value)] #
GToTable (V1 :: Type -> Type) # |
Instance details Defined in Toml.Schema.Generic.ToValue Methods gToTable :: V1 a -> [(Text, Value)] -> [(Text, Value)] #
(GToTable f, GToTable g) => GToTable (f :*: g) # |
Instance details Defined in Toml.Schema.Generic.ToValue Methods gToTable :: (f :*: g) a -> [(Text, Value)] -> [(Text, Value)] #
GToTable f => GToTable (C1 c f) # | Ignores value constructor names
Instance details Defined in Toml.Schema.Generic.ToValue Methods gToTable :: C1 c f a -> [(Text, Value)] -> [(Text, Value)] #
GToTable f => GToTable (D1 c f) # | Ignores type constructor names
Instance details Defined in Toml.Schema.Generic.ToValue Methods gToTable :: D1 c f a -> [(Text, Value)] -> [(Text, Value)] #
(Selector s, ToValue a) => GToTable (S1 s (K1 i (Maybe a) :: Type -> Type)) # | Omits the key from the table on nothing, includes it on just
Instance details Defined in Toml.Schema.Generic.ToValue Methods gToTable :: S1 s (K1 i (Maybe a) :: Type -> Type) a0 -> [(Text, Value)] -> [(Text, Value)] #
(Selector s, ToValue a) => GToTable (S1 s (K1 i a :: Type -> Type)) # | Uses record selector name as table key
Instance details Defined in Toml.Schema.Generic.ToValue Methods gToTable :: S1 s (K1 i a :: Type -> Type) a0 -> [(Text, Value)] -> [(Text, Value)] #

genericToTable :: (Generic a, GToTable (Rep a)) => a -> Table #

Use a record's field names to generate a `Table`

# Product types to Arrays

class GToArray (f :: Type -> Type) where #

Convert product types to arrays positionally.

Methods

gToArray :: f a -> [Value] -> [Value] #

#### Instances

Instances details

(GToArray f, GToArray g) => GToArray (f :*: g) # | Convert left and then right
Instance details Defined in Toml.Schema.Generic.ToValue Methods gToArray :: (f :*: g) a -> [Value] -> [Value] #
ToValue a => GToArray (K1 i a :: Type -> Type) # | Convert fields using `ToValue` instances
Instance details Defined in Toml.Schema.Generic.ToValue Methods gToArray :: K1 i a a0 -> [Value] -> [Value] #
GToArray f => GToArray (M1 i c f) # | Ignore metadata
Instance details Defined in Toml.Schema.Generic.ToValue Methods gToArray :: M1 i c f a -> [Value] -> [Value] #

genericToArray :: (Generic a, GToArray (Rep a)) => a -> Value #

Use a record's field names to generate a `Table`