Toml.Codec.Combinator.Monoid

tomland-1.3.3.3: Bidirectional TOML serialization

Copyright | (c) 2018-2022 Kowainik
License | MPL-2.0
Maintainer | Kowainik <xrom.xkov@gmail.com>
Stability | Stable
Portability | Portable
Safe Haskell | None
Language | Haskell2010

Toml.Codec.Combinator.Monoid

Contents

- Codecs for `Monoid`s
  - Bool wrappers
  - `Num` wrappers
  - `Maybe` wrappers

Description

TOML-specific combinators for converting between TOML and Haskell `Monoid` wrapper data types. These codecs are especially handy when you are implementing the Partial Options Monoid pattern.

Haskell Type | `TOML` | `TomlCodec` | Default on missing field
--- | --- | --- | ---
`All` | `a = true` | ``all` "a"` | ``All` `True``
`Any` | `a = true` | ``any` "a"` | ``Any` `False``
``Sum` `Int`` | `a = 11` | ``sum` `int` "a"` | ``Sum` 0`
``Product` `Int`` | `a = 11` | ``product` `int` "a"` | ``Product` 1`
``First` `Int`` | `a = 42` | ``first` `int` "a"` | ``First` `Nothing``
``Last` `Bool`` | `a = true` | ``last` `bool` "a"` | ``Last` `Nothing``

Since: 1.3.0.0

Synopsis

- all :: Key -> TomlCodec All
- any :: Key -> TomlCodec Any
- sum :: Num a => (Key -> TomlCodec a) -> Key -> TomlCodec (Sum a)
- product :: Num a => (Key -> TomlCodec a) -> Key -> TomlCodec (Product a)
- first :: (Key -> TomlCodec a) -> Key -> TomlCodec (First a)
- last :: (Key -> TomlCodec a) -> Key -> TomlCodec (Last a)

# Codecs for `Monoid`s

## Bool wrappers

all :: Key -> TomlCodec All #

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

Decodes to ``All` `True`` when the key is not present.

Since: 1.2.1.0

any :: Key -> TomlCodec Any #

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

Decodes to ``Any` `False`` when the key is not present.

Since: 1.2.1.0

## `Num` wrappers

sum :: Num a => (Key -> TomlCodec a) -> Key -> TomlCodec (Sum a) #

Codec for `Sum` wrapper for given converter's values.

Decodes to ``Sum` 0` when the key is not present.

Since: 1.2.1.0

product :: Num a => (Key -> TomlCodec a) -> Key -> TomlCodec (Product a) #

Codec for `Product` wrapper for given converter's values.

Decodes to ``Product` 1` when the key is not present.

Since: 1.2.1.0

## `Maybe` wrappers

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

Codec for `First` wrapper for given converter's values.

Decodes to ``First` `Nothing`` when the key is not present.

Since: 1.2.1.0

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

Codec for `Last` wrapper for given converter's values.

Decodes to ``Last` `Nothing`` when the key is not present.

Since: 1.2.1.0