tomland-1.2.1.0: Bidirectional TOML serialization
Copyright(c) 2018-2019 Kowainik
LicenseMPL-2.0
MaintainerKowainik <xrom.xkov@gmail.com>
Safe HaskellNone
LanguageHaskell2010

Toml.Bi.Combinators

Description

Contains TOML-specific combinators for converting between TOML and user data types.

Synopsis

Basic codecs for primitive values

Boolean

bool :: Key -> TomlCodec Bool Source #

Codec for boolean values.

Integral numbers

integer :: Key -> TomlCodec Integer Source #

Codec for integer values.

natural :: Key -> TomlCodec Natural Source #

Codec for natural values.

int :: Key -> TomlCodec Int Source #

Codec for integer values.

word :: Key -> TomlCodec Word Source #

Codec for word values.

word8 :: Key -> TomlCodec Word8 Source #

Codec for word8 values.

Since: 1.2.0.0

Floating point numbers

double :: Key -> TomlCodec Double Source #

Codec for floating point values with double precision.

float :: Key -> TomlCodec Float Source #

Codec for floating point values.

Text types

text :: Key -> TomlCodec Text Source #

Codec for text values.

lazyText :: Key -> TomlCodec Text Source #

Codec for lazy text values.

byteString :: Key -> TomlCodec ByteString Source #

Codec for text values as ByteString.

lazyByteString :: Key -> TomlCodec ByteString Source #

Codec for text values as ByteString.

byteStringArray :: Key -> TomlCodec ByteString Source #

Codec for positive integer array values as ByteString.

Since: 1.2.0.0

lazyByteStringArray :: Key -> TomlCodec ByteString Source #

Codec for positive integer array values as lazy ByteString.

Since: 1.2.0.0

string :: Key -> TomlCodec String Source #

Codec for string values.

Time types

zonedTime :: Key -> TomlCodec ZonedTime Source #

Codec for zoned time values.

localTime :: Key -> TomlCodec LocalTime Source #

Codec for local time values.

day :: Key -> TomlCodec Day Source #

Codec for day values.

timeOfDay :: Key -> TomlCodec TimeOfDay Source #

Codec for time of day values.

Codecs for containers of primitives

arrayOf :: TomlBiMap a AnyValue -> Key -> TomlCodec [a] Source #

Codec for list of values. Takes converter for single value and returns a list of values.

arraySetOf :: Ord a => TomlBiMap a AnyValue -> Key -> TomlCodec (Set a) Source #

Codec for sets. Takes converter for single value and returns a set of values.

arrayIntSet :: Key -> TomlCodec IntSet Source #

Codec for sets of ints. Takes converter for single value and returns a set of ints.

arrayHashSetOf :: (Hashable a, Eq a) => TomlBiMap a AnyValue -> Key -> TomlCodec (HashSet a) Source #

Codec for hash sets. Takes converter for single hashable value and returns a set of hashable values.

arrayNonEmptyOf :: TomlBiMap a AnyValue -> Key -> TomlCodec (NonEmpty a) Source #

Codec for non- empty lists of values. Takes converter for single value and returns a non-empty list of values.

Codecs for Monoids

Bool wrappers

all :: Key -> TomlCodec All Source #

Codec for All wrapper for boolean values. Returns All True on missing fields.

Since: 1.2.1.0

any :: Key -> TomlCodec Any Source #

Codec for Any wrapper for boolean values. Returns Any False on missing fields.

Since: 1.2.1.0

Num wrappers

sum :: (Key -> TomlCodec a) -> Key -> TomlCodec (Sum a) Source #

Codec for Sum wrapper for given converter's values.

Since: 1.2.1.0

product :: (Key -> TomlCodec a) -> Key -> TomlCodec (Product a) Source #

Codec for Product wrapper for given converter's values.

Since: 1.2.1.0

Maybe wrappers

first :: (Key -> TomlCodec a) -> Key -> TomlCodec (First a) Source #

Codec for First wrapper for given converter's values.

Since: 1.2.1.0

last :: (Key -> TomlCodec a) -> Key -> TomlCodec (Last a) Source #

Codec for Last wrapper for given converter's values.

Since: 1.2.1.0

Additional codecs for custom types

textBy :: (a -> Text) -> (Text -> Either Text a) -> Key -> TomlCodec a Source #

Codec for text values with custom error messages for parsing.

read :: (Show a, Read a) => Key -> TomlCodec a Source #

Codec for values with a Read and Show instance.

enumBounded :: (Bounded a, Enum a, Show a) => Key -> TomlCodec a Source #

Codec for general nullary sum data types with a Bounded, Enum, and Show instance. This codec provides much better error messages than read for nullary sum types.

Since: 1.1.1.0

Combinators for tables

table :: forall a. TomlCodec a -> Key -> TomlCodec a Source #

Codec for tables. Use it when when you have nested objects.

nonEmpty :: forall a. TomlCodec a -> Key -> TomlCodec (NonEmpty a) Source #

Codec for NonEmpty list of values. Represented in TOML as array of tables.

list :: forall a. TomlCodec a -> Key -> TomlCodec [a] Source #

Codec for list of values. Represented in TOML as array of tables.

set :: forall a. Ord a => TomlCodec a -> Key -> TomlCodec (Set a) Source #

Codec for set of values. Represented in TOML as array of tables.

Since: 1.2.0.0

hashSet :: forall a. (Hashable a, Eq a) => TomlCodec a -> Key -> TomlCodec (HashSet a) Source #

Codec for HashSet of values. Represented in TOML as array of tables.

Since: 1.2.0.0

Combinators for Maps

map Source #

Arguments

:: forall k v. Ord k 
=> TomlCodec k

Codec for Map keys

-> TomlCodec v

Codec for Map values

-> Key

TOML key where Map is stored

-> TomlCodec (Map k v)

Codec for the Map

Bidirectional codec for Map. It takes birectional converter for keys and values and produces bidirectional codec for Map. Currently it works only with array of tables, so you need to specify Maps in TOML files like this:

myMap =
    [ { name = "foo", payload = 42 }
    , { name = "bar", payload = 69 }
    ]

TomlCodec for such TOML field can look like this:

Toml.map (Toml.text "name") (Toml.int "payload") "myMap"

If there's no key with the name "myMap" then empty Map is returned.

Since: 1.2.1.0

General construction of codecs

match :: forall a. TomlBiMap a AnyValue -> Key -> TomlCodec a Source #

General function to create bidirectional converters for key-value pairs. In order to use this function you need to create TomlBiMap for your type and AnyValue:

_MyType :: TomlBiMap MyType AnyValue

And then you can create codec for your type using match function:

myType :: Key -> TomlCodec MyType
myType = match _MyType