type Output = Result<{ error: string }, { message: string }>;
const divide = (value: number, by: number): Output => {
if (by === 0) {
return Result.Err({ error: "Divisão por zero" });
}
return Result.Ok({ message: `Resultado: ${value / by}` });
};
const result = divide(10, 2);
if (result.isOk) {
console.log(result.value.message);
} else {
console.log(result.value.error);
}
-
Notifications
You must be signed in to change notification settings - Fork 0
License
mpgxc/result.monad
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
No description or website provided.
Topics
Resources
License
Stars
Watchers
Forks
Packages 0
No packages published