Map over a Result instance as in map and get out the value if result is an Ok, or return a default value if result is an Err.
Result
map
result
Ok
Err
import { ok, err, mapOr } from 'true-myth/result';const length = (s: string) => s.length;const anOkString = ok('a string');const theStringLength = mapOr(0, anOkString);console.log(theStringLength); // 8const anErr = err('uh oh');const anErrMapped = mapOr(0, anErr);console.log(anErrMapped); // 0 Copy
import { ok, err, mapOr } from 'true-myth/result';const length = (s: string) => s.length;const anOkString = ok('a string');const theStringLength = mapOr(0, anOkString);console.log(theStringLength); // 8const anErr = err('uh oh');const anErrMapped = mapOr(0, anErr);console.log(anErrMapped); // 0
The default value to use if result is an Err.
The function to apply the value to if result is an Ok.
The Result instance to map over.
Generated using TypeDoc
Map over a
Result
instance as inmap
and get out the value ifresult
is anOk
, or return a default value ifresult
is anErr
.Examples