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:
This TomlCodec helps you to convert TOML key-value pairs
directly to Map using TOML keys as Map keys. It can be convenient
if your Map keys are types like Text or Int and you want to work with raw
TOML keys directly.
For example, if you have TOML like this:
[colours]
yellow = "#FFFF00"
red = { red = 255, green = 0, blue = 0 }
pink = "#FFC0CB"
You want to convert such TOML configuration into the following Haskell
types:
data Rgb = Rgb
{ rgbRed :: Int
, rgbGreen :: Int
, rgbBlue :: Int
}
data Colour
= Hex Text
| RGB Rgb
colourCodec :: TomlCodec Colour
colourCodec = ...
data ColourConfig = ColourConfig
{ configColours :: MapText Colour
}
And you want in the result to have a Map like this:
Hint: You can use Toml.Codec.BiMap._KeyText or
Toml.Codec.BiMap._KeyString to convert betwen TOML keys and Map
keys (or you can write your custom TomlBiMap).
NOTE: Unlike the map codec, this codec is less flexible (i.e. it doesn't
allow to have arbitrary structures as Keys, it works only for
text-like keys), but can be helpful if you want to save a few
keystrokes during TOML configuration. A similar TOML configuration,
but suitable for the map codec will look like this:
Bidirectional codec for HashMap. It takes birectional converter for keys and
values and produces bidirectional codec for HashMap. It works with array of
tables, so you need to specify HashMaps in TOML files like this:
This TomlCodec helps to convert TOML key-value pairs
directly to HashMap using TOML keys as HashMap keys.
It can be convenient if your HashMap keys are types like Text or Int and
you want to work with raw TOML keys directly.
For example, if you can write your HashMap in TOML like this:
Bidirectional codec for IntMap. It takes birectional converter for keys and
values and produces bidirectional codec for IntMap. It works with array of
tables, so you need to specify IntMaps in TOML files like this: