Map over a Result instance as in map and get out the
value if result is Ok, or apply a function (orElseFn) to the
value wrapped in the Err to get a default value.
Like mapOr but using a function to transform the error into a
usable value instead of simply using a default value.
constokResponse = ok("Things are grand here."); constmappedOkAndUnwrapped = mapOrElse(getReason, summarize, okResponse); console.log(mappedOkAndUnwrapped); // The response was: 'Things are grand here.'
consterrResponse = err({ code:500, reason:'Nothing at this endpoint!' }); constmappedErrAndUnwrapped = mapOrElse(getReason, summarize, errResponse); console.log(mappedErrAndUnwrapped); // Nothing at this endpoint!
Map over a
Result
instance as inmap
and get out the value ifresult
isOk
, or apply a function (orElseFn
) to the value wrapped in theErr
to get a default value.Like
mapOr
but using a function to transform the error into a usable value instead of simply using a default value.Examples