Maps a successful Result value using the provided function. If the Result is an error, returns the error unchanged.
The type of the input value
The type of the output value
The type of the error
The Result to map
Function to transform the successful value
A new Result with the transformed value, or the original error
const result = ok(5)const doubled = map(result, x => x * 2) // ok(10)const errorResult = err(new Error("Failed"))const mapped = map(errorResult, x => x * 2) // err(Error("Failed")) Copy
const result = ok(5)const doubled = map(result, x => x * 2) // ok(10)const errorResult = err(new Error("Failed"))const mapped = map(errorResult, x => x * 2) // err(Error("Failed"))
Maps a successful Result value using the provided function. If the Result is an error, returns the error unchanged.