Applies a mapper to an optional value.
Extends a mapper with a tolerance for undefined values: a defined value is handed on to it stripped of undefined,
while an undefined one short-circuits to undefined without calling it, so an optional value flows through a chain
of total functions without a guard at every step.
Unlike optional chaining, this covers an arbitrary mapper rather than property access alone, and short-circuits on
undefined alone: definedness is about assignment rather than emptiness, so null is mapped like any other value.
The type of the value to map, possibly including undefined
The type of the value reported by mapper
undefined if value is undefined, and the value computed from value by mapper otherwise; errors
raised by mapper propagate to the caller unchanged
Applies a mapper to an optional value, falling back to a default.
Closes the undefined case with a value of its own, so the result is defined whatever the input: a defined value is
mapped as above, while an undefined one reports fallback without calling the mapper. This states a total
computation in one call, where the two-argument form would leave the caller to close the gap with ??.
The fallback may be deferred as a no-arg function, matching the short-circuiting ?? supplies: a deferred fallback
is resolved only if the value is actually undefined, so a costly default is not computed on the mapped path.
A fallback supplied as a function is always taken as a deferred one. Where R is itself a function type, wrap the
default in a thunk reporting it (() => fallback), or it is called instead of being reported.
The type of the value to map, possibly including undefined
The type of the value reported by mapper and of the fallback
The value computed from value by mapper if value is defined, and fallback otherwise; errors raised
by mapper or by a deferred fallback propagate to the caller unchanged
Applies a mapper to an optional value, short-circuiting an undefined one.