promise-option
@sandlada/result/promise-option — eager operators on Promise<IOption<T>>.
- Operates on:
Promise<IOption<T>>; callbacks may be synchronous or asynchronous depending on the operator. - Execution model: eager — the chain starts on the call and the returned Promise is already in flight.
- Not here: sync Option operators (
option), lazy thunks (async-option), Result variants (promise-result).
Constructors (re-exported)
Section titled “Constructors (re-exported)”| Export | Description | Source |
|---|---|---|
asyncOk / asyncErr |
Pre-resolved Result Promises from factories. |
../factories/asyncOk.ts, ../factories/asyncErr.ts |
ofSome / ofNone |
Sync Option constructors from option. |
../option/ofSome.ts, ../option/ofNone.ts |
Operators on Promise<IOption>
Section titled “Operators on Promise<IOption>”| Export | Description | Source |
|---|---|---|
mapAsyncOption |
Transforms the Some value with an async callback. |
mapAsyncOption.ts |
bindAsyncOption |
Async chain returning the next Option. | bindAsyncOption.ts |
orElseAsyncOption |
Async fallback on None. |
orElseAsyncOption.ts |
matchAsyncOption |
Async terminal pattern match. | matchAsyncOption.ts |
mapOrAsyncOption / mapOrElseAsyncOption |
Map the Some value or fall back asynchronously. |
mapOrAsyncOption.ts, mapOrElseAsyncOption.ts |
tapAsyncOption / tapErrAsyncOption |
Async side effects. | tapAsyncOption.ts, tapErrAsyncOption.ts |
unwrapOrAsyncOption / unwrapOrElseAsyncOption |
Extract the value or an async default. | unwrapOrAsyncOption.ts, unwrapOrElseAsyncOption.ts |
containsAsyncOption / existsAsyncOption / filterAsyncOption |
Async predicate queries. | containsAsyncOption.ts, existsAsyncOption.ts, filterAsyncOption.ts |
flattenAsyncOption |
Flattens Promise<IOption<IOption<T>>>. |
flattenAsyncOption.ts |
Lift sync IOption → async
Section titled “Lift sync IOption → async”| Export | Description | Source |
|---|---|---|
asyncMapOption |
Async map on a sync IOption. |
asyncMapOption.ts |
asyncBindOption |
Async chain on a sync IOption. |
asyncBindOption.ts |
asyncOrElseOption |
Async fallback on a sync IOption. |
asyncOrElseOption.ts |
asyncMatchOption |
Async terminal match on a sync IOption. |
asyncMatchOption.ts |
asyncTapOption |
Async side effect on a sync IOption. |
asyncTapOption.ts |
Contract notes
Section titled “Contract notes”- A rejection of the outer
Promiseitself always stays a rejection; it is never converted intoNone. - Callback policy: operators on
Promise<IOption>collapse a throwing callback or an async rejection intoNone/false/ the default value;matchAsyncOption,mapOrElseAsyncOptionandunwrapOrElseAsyncOptionpropagate instead. The lifting family (asyncMapOption,asyncBindOption,asyncTapOption,asyncOrElseOption) turns a synchronous throw intoNonebut lets a rejected Promise propagate. See behavior-modes.md §4.6. - This layer has no
unwrap/expect/orThrow; extraction goes through theunwrapOr*family. - There are no combination APIs here; combine Options with the sync
option/allbefore lifting when needed. - Naming: the
AsyncOptionsuffix marks operators that consume aPromise<IOption>; theasync*Optionprefix marks the lift family that consumes a synchronousIOption.
Design notes
Section titled “Design notes”- Eager and lazy async are separate modules.
promise-optionmirrorspromise-resulton the Option track, whileasync-optionprovides the lazy thunk counterpart.
Related
Section titled “Related”option— the synchronous operator set.async-option— the lazy thunk counterpart.promise-result— the same shape on the Result track.