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

Description

TOML-specific combinators for converting between TOML and Haskell tuples. It's recommended to create your custom data types and implement codecs for them, but if you need to have tuples (e.g. for decoding different constructors of sum types), you can find codecs from this module helpful.

Haskell Type | `TOML` | `TomlCodec`
--- | --- | ---
`(`Int`, `Text`)` | `[foo]` | ``pair``
| `a = 42` | `(`int` "a")`
| `b = "bar"` | `(`text` "b")`
`(`Int`, `Text`, `Bool`)` | `[foo]` | ``triple``
| `a = 42` | `(`int` "a")`
| `b = "bar"` | `(`text` "b")`
| `c = false` | `(`bool` "c")`

Since: 1.3.0.0

Synopsis

- pair :: TomlCodec a -> TomlCodec b -> TomlCodec (a, b)
- triple :: TomlCodec a -> TomlCodec b -> TomlCodec c -> TomlCodec (a, b, c)

# Documentation

pair :: TomlCodec a -> TomlCodec b -> TomlCodec (a, b) #

Codec for pair of values. Takes codecs for the first and for the second values of the pair.

If I have the following `TOML` entry

    myPair = { first = 11, second = "eleven"}

and want to convert it into the Haskell tuple of two elements, I can use the following codec:

    myPairCodec :: TomlCodec (Int, Text)
    myPairCodec = flip Toml.table "myPair" $ Toml.pair
        (Toml.int "first")
        (Toml.text "second")

Since: 1.3.0.0

triple :: TomlCodec a -> TomlCodec b -> TomlCodec c -> TomlCodec (a, b, c) #

Codec for triple of values. Takes codecs for the first, second and third values of the triple.

If I have the following `TOML` entry

    myTriple =
        { first = 11
        , second = "eleven"
        , isMyFavourite = true
        }

and want to convert it into the Haskell tuple of three elements, I can use the following codec:

    myTripleCodec :: TomlCodec (Int, Text, Bool)
    myTripleCodec = flip Toml.table "myTriple" $ Toml.triple
        (Toml.int "first")
        (Toml.text "second")
        (Toml.bool "isMyFavourite")

Since: 1.3.0.0