🏃‍♂️Result

Represents the result of an operation that can either succeed with a value or fail with an error.

const orResult: Result<number, string> = ok(42);
const errorResult: Result<number, string> = error("An error occurred");

orResult.get(); // Returns 42
errorResult.get(); // Throws Error("An error occurred")

orResult.extract(); // Returns {value: 42}
errorResult.extract(); // Returns {error: "An error occurred"}

orResult.toOptional(); // Optional with value 42
errorResult.toOptional(); // Optional with no value

Last updated