zio-config icon indicating copy to clipboard operation
zio-config copied to clipboard

Add ConfigSource.mapAt

Open jdegoes opened this issue 3 years ago • 0 comments

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))
  ...
}

jdegoes avatar Nov 02 '21 18:11 jdegoes