Cheatsheet — Core operators
The everyday operators for composing Option/Result pipelines—plus quick examples you can expand.
These are the handful of operators you'll reach for constantly when building pipelines with Result and Option. Each row includes a short "at-a-glance" usage snippet; click the code button to open a fuller example you can copy and adapt.
Core operators
| Operator | Description | Usage |
|---|---|---|
map | Transform the inner value on the happy path | Ok(2).map(n => n+1) → Ok(3) |
flatMap | Chain a function that returns Option/Result | Some(2).flatMap(fn) → Some(2) |
zip | Pair the current value with a derived value | Ok("id").zip(fn) → Ok([...]) |
flatZip | Pair with a derived Option/Result | Some(x).flatZip(fn) → Some([...]) |
toPromise | Resolve async values inside the container | Ok(promise).toPromise() |
innerMap | Map over an inner array | Ok([1,2]).innerMap(fn) → Ok([2,4]) |
tap | Side effect for Ok/Some, returns self | Ok(1).tap(console.log) |
Notes
- Many operators have sync + async overloads; when you return a
Promise, you typically end up withOption<Promise<T>>orResult<Promise<T>, E>and then calltoPromise()to materialize.
Reference (generated)
Option
Prop
Type
Result
Prop
Type