Skip to main content

swappedNullishOrFn()

swappedNullishOrFn<T, A>(a): <B>(b) => (c) => A | NonNullable<B>

Swapped Nullish Coalescing (b(x) ?? a(x)).

Type Parameters

T

The type of the input value of the functions.

A

The return type of the first function.

Parameters

a

(x) => A

The function to get the fallback return of.

Returns

Function

Type Parameters

B

Parameters

b

(y) => B

Returns

Function

Parameters

c

T

Returns

A | NonNullable<B>

Remark

pure function

Example

swappedNullishOrFn(x => x.bar)(x => x.foo)({ bar: 4 });
// 4