MCPcopy Create free account
hub / github.com/Effect-TS/effect / withDefault

Function withDefault

packages/effect/src/SchemaGetter.ts:662–669  ·  view source on GitHub ↗
(
  defaultValue: Effect.Effect<T, SchemaIssue.Issue, R>
)

Source from the content-addressed store, hash-verified

660 * @since 4.0.0
661 */
662export function withDefault<T, R = never>(
663 defaultValue: Effect.Effect<T, SchemaIssue.Issue, R>
664): Getter<T, T | undefined, R> {
665 return new Getter((o) => {
666 const filtered = Option.filter(o, Predicate.isNotUndefined)
667 return Option.isSome(filtered) ? Effect.succeed(filtered) : Effect.mapEager(defaultValue, Option.some)
668 })
669}
670
671/**
672 * Coerces any value to a `string` using the global `String()` constructor.

Callers 1

optionFunction · 0.85

Calls 2

filterMethod · 0.80
succeedMethod · 0.45

Tested by

no test coverage detected