dmmulroy/better-result ? reverse-engineered prompt
Reverse engineered prompt
Build me a lightweight Result type library for TypeScript, similar to Rust, so I can handle errors without using try catch everywhere.
I want to be able to wrap sync and async work, create ok and err values, check them with helpers, match on them, and transform them with map, mapError, and andThen. Please also support generator based composition so I can chain several Result operations without nested callbacks or early returns. It should work nicely with both plain functions and promises, and include helpers for unwrap, unwrapOr, tap, and retry for async calls.
Make it feel really polished to use, with strong TypeScript types so error unions are preserved and inferred well. If it makes sense, add tagged custom errors and a few examples in the README showing the main patterns. Look up current docs online if you need to.