Skip to content

defaultTo

defaultTo<B>(fallback): <A>(a) => B | NonNullable<A>

Defined in: Composition/fn.ts:113

Returns a fallback value if the input is null or undefined; otherwise returns the input value. Highly useful as a data-last default value step inside pipelines.

B

B

<A>(a) => B | NonNullable<A>

const getName = flow(
  (u: { name?: string | null }) => u.name,
  defaultTo("Guest"),
  name => name.toUpperCase()
); // returns string