Skip to content

Commit

Permalink
Introduce map and mapEither
Browse files Browse the repository at this point in the history
  • Loading branch information
afsalthaj committed Aug 3, 2022
1 parent f65c80a commit 5809fe0
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions core/shared/src/main/scala/zio/config/ConfigDescriptorModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,30 @@ trait ConfigDescriptorModule extends ConfigSourceModule { module =>
final def from(that: ConfigSource): ConfigDescriptor[A] =
self.updateSource(_.orElse(that))

/**
* Transform A to B, however usage of map disallows the usage of `write` back
* functionality.
*
* Use `map` if we really don't care writing back the config to the sources in future
*/
final def map[B](f: A => B): ConfigDescriptor[B] =
self.transformOrFailRight[B](
f,
_ => Left("Unable to write back the config. Use transform methods instead of map to specify how to write back")
)

/**
* Transform A to B that can fail, however usage of mapEither disallows the usage of `write` back
* functionality.
*
* Use `mapEither` if we really don't care writing back the config to the sources in future
*/
final def mapEither[B](f: A => Either[String, B]): ConfigDescriptor[B] =
self.transformOrFail[B](
f,
_ => Left("Unable to write back the config. Use transform methods instead of map to specify how to write back")
)

/**
* mapKey allows user to convert the keys in a ConfigDescriptor.
*
Expand Down

0 comments on commit 5809fe0

Please sign in to comment.