Skip to content

getOrElse

getOrElse<A, B>(defaultValue): (data) => A | B

Defined in: Core/Maybe.ts:184

Returns the value inside an Maybe, or a default value if None. The default is a thunk () => B — evaluated only when the Maybe is None. The default can be a different type, widening the result to A | B.

A

B

() => B

(data): A | B

Maybe<A>

A | B

pipe(Maybe.some(5), Maybe.getOrElse(() => 0)); // 5
pipe(Maybe.none(), Maybe.getOrElse(() => 0)); // 0
pipe(Maybe.none<string>(), Maybe.getOrElse(() => null)); // null — typed as string | null