You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not all Result use-cases need an actual Error object to represent the error. Sometimes you might just want to return a string. The Result monad should be refactored to accept two generic times: one for the result and one for the error. It should use an underlying union type to determine what is a result and what is an error.
// A function that returns a Result containing either the parsed number, or an error message.functionparseNumber(str: string): Result<number,string>{constparsed=parseInt(str):
if(isNaN(parsed)){returnResult.ofError("Parsed string was not a number!");}returnResult.ofValue(parsed);}
The text was updated successfully, but these errors were encountered:
Any Result function that could conceivably throw an error (e.g. Result.ofFunction or Result.ofPromise) should require a callback function that would specifically map the error into something. We want to guarantee that the error value of a Result is what the compiler says it is.
Not all
Result
use-cases need an actualError
object to represent the error. Sometimes you might just want to return a string. TheResult
monad should be refactored to accept two generic times: one for the result and one for the error. It should use an underlying union type to determine what is a result and what is an error.The text was updated successfully, but these errors were encountered: