zio-config
zio-config copied to clipboard
Add ConfigSource.mapAt
A mapAt
allows you to drill into a part of a ConfigSource
and apply changes (such as mapKeys
) to only that part.
To implement this, I think we can benefit from:
ConfigSource#without(path) // removes a path
ConfigSource#merge(that) // merges two config sources
ConfigSource#nest(path) // nests a config source at the provided location (opposite of .at)
From these, we can build a mapAt
in a compositional fashion:
trait ConfigSource {
def mapAt(path: PropertyTreePath[K])(f: ConfigSource => ConfigSource): ConfigSource =
self.without(path).merge(f(self.at(path)).nest(path))
...
}