carbonteq /FP

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

OperatorDescriptionUsage
mapTransform the inner value on the happy path
Ok(2).map(n => n+1) → Ok(3)
flatMapChain a function that returns Option/Result
Some(2).flatMap(fn) → Some(2)
zipPair the current value with a derived value
Ok("id").zip(fn) → Ok([...])
flatZipPair with a derived Option/Result
Some(x).flatZip(fn) → Some([...])
toPromiseResolve async values inside the container
Ok(promise).toPromise()
innerMapMap over an inner array
Ok([1,2]).innerMap(fn) → Ok([2,4])
tapSide 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 with Option<Promise<T>> or Result<Promise<T>, E> and then call toPromise() to materialize.

Reference (generated)

Option

Prop

Type

Result

Prop

Type

On this page