Toml.Codec.Combinator.Set

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.Set

Contents

- Array sets
- Table Sets

Description

TOML-specific combinators for converting between TOML and Haskell Set-like data types.

There are two way to represent list-like structures with the `tomland` library.

- Ordinary array sets of primitives:

      foo = [100, 200, 300]

- Sets via tables:

      foo =
          [ {x = 100}
          , {x = 200}
          , {x = 300}
          ]

      OR

      [[foo]]
          x = 100
      [[foo]]
          x = 200
      [[foo]]
          x = 300

You can find both types of the codecs in this module for different set-like structures. See the following table for the better understanding:

Haskell Type | `TOML` | `TomlCodec`
--- | --- | ---
``Set` `Text`` | `a = ["foo", "bar", "baz"]` | ``arraySetOf` `_Text` "a"`
`IntSet` | `a = [11, 42]` | ``arrayIntSet` "a"`
``HashSet` `Text`` | `a = ["foo", "bar"]` | ``arrayHashSetOf` `_Text` "a"`
``Set` `Text`` | `x = [{a = "foo"}, {a = "bar"}]` | ``set` (`text` "a") "x"`
``HashSet` `Text`` | `x = [{a = "foo"}, {a = "bar"}]` | ``hashSet` (`text` "a") "x"`

Since: 1.3.0.0

Synopsis

- arraySetOf :: Ord a => TomlBiMap a AnyValue -> Key -> TomlCodec (Set a)
- arrayIntSet :: Key -> TomlCodec IntSet
- arrayHashSetOf :: Hashable a => TomlBiMap a AnyValue -> Key -> TomlCodec (HashSet a)
- set :: Ord a => TomlCodec a -> Key -> TomlCodec (Set a)
- intSet :: TomlCodec Int -> Key -> TomlCodec IntSet
- hashSet :: Hashable a => TomlCodec a -> Key -> TomlCodec (HashSet a)

# Array sets

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

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

Example:

Haskell ``Set` `Int`` can look like this in your `TOML` file:

    foo = [1, 2, 3]

In case of the missing field, the following error will be seen:

    tomland decode error:  Key foo is not found

Since: 0.5.0

arrayIntSet :: Key -> TomlCodec IntSet #

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

Example:

Haskell ``IntSet`` can look like this in your `TOML` file:

    foo = [1, 2, 3]

In case of the missing field, the following error will be seen:

    tomland decode error:  Key foo is not found

Since: 0.5.0

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

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

Example:

Haskell ``HashSet` `Int`` can look like this in your `TOML` file:

    foo = [1, 2, 3]

In case of the missing field, the following error will be seen:

    tomland decode error:  Key foo is not found

Since: 0.5.0

# Table Sets

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

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

Example:

Haskell ``Set` `Int`` can look like this in your `TOML` file:

    foo =
      [ {a = 1}
      , {a = 2}
      ]

Decodes to an empty `Set` in case of the missing field in `TOML`.

Since: 1.2.0.0

intSet :: TomlCodec Int -> Key -> TomlCodec IntSet #

`Codec` for `IntSet`. Represented in TOML as an array of tables.

Example:

Haskell `IntSet` can look like this in your `TOML` file:

    foo =
      [ {a = 1}
      , {a = 2}
      ]

Decodes to an empty `IntSet` in case of the missing field in `TOML`.

Since: 1.3.0.0

hashSet :: Hashable a => TomlCodec a -> Key -> TomlCodec (HashSet a) #

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

Example:

Haskell ``HashSet` `Int`` can look like this in your `TOML` file:

    foo =
      [ {a = 1}
      , {a = 2}
      ]

Decodes to an empty `HashSet` in case of the missing field in `TOML`.

Since: 1.2.0.0