Hyperlinkv0.8.0-beta.28

ConfigProvider

ConfigProvider.mapInputconsteffect/ConfigProvider.ts:488
(f: (path: Path) => Path): (self: ConfigProvider) => ConfigProvider
(self: ConfigProvider, f: (path: Path) => Path): ConfigProvider

Transforms the path segments before they reach the underlying store.

When to use

Use when you need to rename, re-case, or otherwise transform config path segments before lookup.

Details

The function f receives the whole path produced by earlier provider transformations and must return a new path. Lookup path transformations compose in application order: the existing transformation runs first, then f runs. For providers composed with orElse, the transformation is applied to each operand.

Example (Uppercasing path segments)

import { ConfigProvider } from "effect"

const provider = ConfigProvider.fromEnv({
  env: { APP_HOST: "localhost" }
})

const upper = ConfigProvider.mapInput(provider, (path) =>
  path.map((seg) =>
    typeof seg === "string" ? seg.toUpperCase() : seg
  )
)
export const mapInput: {
  (f: (path: Path) => Path): (self: ConfigProvider) => ConfigProvider
  (self: ConfigProvider, f: (path: Path) => Path): ConfigProvider
} = dual(
  2,
  (self: ConfigProvider, f: (path: Path) => Path): ConfigProvider => {
    const state = self.state
    switch (state._tag) {
      case "Source":
        return makeSource(state.get, flow(state.transform, f))
      case "OrElse":
        return makeOrElse(mapInput(state.first, f), mapInput(state.second, f))
    }
  }
)
Referenced by 1 symbols