Skip to content

async-option

@sandlada/result/async-option — operators on the lazy AsyncOption<T> thunk.

  • Operates on: AsyncOption<T> — a plain object { readonly run: () => Promise<IOption<T>> }.
  • Execution model: lazy — middleware returns a new thunk without running anything; terminals such as match / unwrap / unwrapOr return a Promise and call run() immediately.
  • Not here: eager Promises (promise-option), sync operators (option), Result carriers (async-result).
Export Description Source
from Wraps a thunk returning an Option (or a plain Option) into an AsyncOption. from.ts
fromPromise Wraps a thunk returning Promise<IOption>; a throw or rejection becomes None. fromPromise.ts
fromOption Lifts a synchronous IOption into an AsyncOption. fromOption.ts
ofSome / ofNone Direct Some / None constructors. ofSome.ts, ofNone.ts
Export Description Source
map / mapAsync Transform the Some value with a sync / async callback. map.ts, mapAsync.ts
mapOr / mapOrElse Map the Some value or fall back. mapOr.ts, mapOrElse.ts
filter Turns Some into None when the predicate fails. filter.ts
flatten Flattens a nested AsyncOption. flatten.ts
transpose Swaps AsyncOption<AsyncResult> and AsyncResult<AsyncOption>. transpose.ts
Export Description Source
bind Monadic chain: the callback returns the next AsyncOption. bind.ts
orElse Fallback on None. orElse.ts
Export Description Source
tap / tapAsync Side effects on Some. tap.ts, tapAsync.ts
Export Description Source
contains Equality check against the Some value. contains.ts
exists Predicate check on the Some value. exists.ts
isSome / isNone Standalone boolean predicates. isSome.ts, isNone.ts
Export Description Source
all Combines many AsyncOptions; an empty array is Some([]). all.ts
zipWith Combines N≥2 AsyncOptions with a function (explicit arities 2–10, mapped type beyond). zipWith.ts
Export Description Source
okOr / okOrElse Some becomes Ok; None becomes Err(error) / Err(errorFn()). okOr.ts, okOrElse.ts
Export Description Source
match Pattern match over Some / None; triggers run(). match.ts
unwrap Terminal contract panic; the only panic API in this module. unwrap.ts
unwrapOr / unwrapOrElse Extract the value or fall back; triggers run(). unwrapOr.ts, unwrapOrElse.ts
  • Nothing runs until a terminal calls run(); middleware returns a new thunk.
  • mapAsync captures fully here, the opposite of async-result/mapAsync: a sync throw or rejected Promise becomes None. match, mapOrElse, unwrapOrElse, exists and zipWith propagate instead. See behavior-modes.md §4.7.
  • all starts every carrier through Promise.all once run() is called; any None selects None, but every side effect still happens.
  • zipWith resolves to None when any argument is None.
  • The module has only unwrap as a panic API; there is no expect or orThrow. Bridge to AsyncResult with okOr / okOrElse when a typed throw is required.
  • Naming: the async prefix denotes the AsyncOption type, not the async/await keyword.
  • Eager and lazy async are separate modules. async-option mirrors async-result on the Option track, while promise-option operates on Promises already in flight.