kowainik / tomland

🏝 Bidirectional TOML serialization
https://kowainik.github.io/posts/2019-01-14-tomland
Mozilla Public License 2.0
120 stars 39 forks source link

Add _Hardcoded `TomlBiMap` #329

Closed chshersh closed 3 years ago

chshersh commented 4 years ago

Sometimes it's required to be able to decode a single key-value pair where only one value is allowed. Like in the example below:

scope = "all"

This is useful for decoding sum types. I propose to add necessary utils for this:

_Hardcoded :: (Eq a, Show a) => a -> TomlBiMap () a

And later users can use this TmlBiMap (for the above example) like this:

Toml.match (Toml._Hardcoded "all" >>> Toml._Text) "scope"