dimap This is an instance of Profunctor for Codec. But since there's no
Profunctor type class in base or package with no dependencies (and we don't
want to bring extra dependencies) this instance is implemented as a single
top-level function.
Useful when you want to parse newtypes. For example, if you had data type like
this:
data Example = Example
{ foo :: Bool
, bar :: Text
}
Bidirectional TOML converter for this type will look like this:
exampleCodec :: TomlCodec Example
exampleCodec = Example
<$> Toml.bool "foo" .= foo
<*> Toml.text "bar" .= bar
Now if you change your type in the following way:
newtype Email = Email { unEmail :: Text }
data Example = Example
{ foo :: Bool
, bar :: Email
}
you need to patch your TOML codec like this:
exampleCodec :: TomlCodec Example
exampleCodec = Example
<$> Toml.bool "foo" .= foo
<*> dimap unEmail Email (Toml.text "bar") .= bar