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

Toml.Codec.Combinator.Set

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

Array sets

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.

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 Source #

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

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 :: forall a. Ord a => TomlCodec a -> Key -> TomlCodec (Set a) Source #

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 Source #

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 :: forall a. (Hashable a, Eq a) => TomlCodec a -> Key -> TomlCodec (HashSet a) Source #

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