adapters
{/* @generated by scripts/sync-content.mjs; do not edit */}
@sandlada/result/adapters — bridges between plain functions / values and the Result railway.
- Operates on: the boundary between single-track values or plain functions and two-track Results / Options.
- Execution model: synchronous, except
switchFnAsync/teeAsync, which await a Promise-returning callback. - Not here: Result operators (
operators), Option operators (option).
Function shape
Section titled “Function shape”| Export | Description | Source |
|---|---|---|
switchFn |
Wraps a plain function into a function returning IResultOfT; a throw is captured as Err. |
switchFn.ts |
switchFnAsync |
Wraps a Promise-returning plain function into a function returning Promise<IResultOfT>. |
switchFnAsync.ts |
tee |
Single-track side effect: runs the callback and returns the input value unchanged. | tee.ts |
teeAsync |
Async single-track side effect: awaits the callback and returns the input value unchanged. | teeAsync.ts |
Result ↔ Option
Section titled “Result ↔ Option”| Export | Description | Source |
|---|---|---|
toOption |
Ok(value) becomes Some(value); Err becomes None, discarding the error. |
toOption.ts |
fromOption |
Some(value) becomes Ok(value); None becomes Err(error). |
fromOption.ts |
Contract notes
Section titled “Contract notes”switchFn/switchFnAsynccapture to values, including a second collapse whenerrorFnitself throws.tee/teeAsyncpropagate directly — there is no failure state to convert.toOption/fromOptionnever throw;fromOptionneeds an error value (or factory) for theNonebranch.- Throw policy: behavior-modes.md §4.4.
Related
Section titled “Related”operators— the operators these adapters feed into.option— Option-side operators, includingokOr/transposebridges.primitives—lift, the dual-state alternative toswitchFn.