Hyperlinkv0.8.0-beta.28

Config

Config.orElseconsteffect/Config.ts:231
<A2>(that: (error: ConfigError) => Config<A2>): <A>(
  self: Config<A>
) => Config<A2 | A>
<A, A2>(
  self: Config<A>,
  that: (error: ConfigError) => Config<A2>
): Config<A | A2>

Provides a fallback config when parsing fails with a ConfigError.

When to use

Use when you need to try an alternative config source after the primary one fails.

Details

Unlike withDefault, this catches all ConfigErrors (not just missing data). The fallback function receives the error and returns a new Config.

Example (Falling back to a literal)

import { Config } from "effect"

const hostConfig = Config.string("HOST").pipe(
  Config.orElse(() => Config.succeed("localhost"))
)
combinatorswithDefault
Source effect/Config.ts:2318 lines
export const orElse: {
  <A2>(that: (error: ConfigError) => Config<A2>): <A>(self: Config<A>) => Config<A2 | A>
  <A, A2>(self: Config<A>, that: (error: ConfigError) => Config<A2>): Config<A | A2>
} = dual(2, <A, A2>(self: Config<A>, that: (error: ConfigError) => Config<A2>): Config<A | A2> => {
  return make((provider, pathPrefix) =>
    Effect.catch(self.parse(provider, pathPrefix), (error) => that(error).parse(provider, pathPrefix))
  )
})
Referenced by 1 symbols