From e9a11515adc44e53a99ba442a7a1842dc1496624 Mon Sep 17 00:00:00 2001 From: Anton Nesterov Date: Thu, 17 Oct 2024 06:06:54 +0200 Subject: [PATCH] update readm --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index 60cff77..3abbf73 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,34 @@ Simplified result/error handling for JavaScript. Grip always returns a consistent call result ready to be handled. It makes the control flow similar to that of Golang, but doesn't force you to make additional null checks or create transitional variables to hold error results. +Instead of returning an nullish Error, Grip always returns a Status object: + +```javascript +const [value, status] = grip(callable) +if (status.Fail()) { + // handle any error +} +if (status.Of(MySpecificError)) { + // handle specific error +} +``` + +The call result is better than tuple: + +```javascript +const result = grip(callable) +if (result.Fail()) { + // handle any error +} +if (result.Of(MySpecificError)) { + // handle specific error +} + +console.log(result.value) // result[0] +``` + +Grip also works with Promises, functions that return promises, generators and async generators. + ## Install ```bash