Skip to content

getOrElse

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

Defined in: Core/Validation.ts:176

Returns the success value or a default value if the Validation is invalid. The default can be a different type, widening the result to A | B.

E

A

B

() => B

(data): A | B

Validation<E, A>

A | B

pipe(Validation.valid(5), Validation.getOrElse(() => 0)); // 5
pipe(Validation.invalid("oops"), Validation.getOrElse(() => 0)); // 0
pipe(Validation.invalid("oops"), Validation.getOrElse(() => null)); // null — typed as number | null