Skip to content

adapters

@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).
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
liftMap Semantic alias of operators/map for lifting a plain function onto the success track. liftMap.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
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
  • switchFn / switchFnAsync capture to values, including a second collapse when errorFn itself throws; liftMap delegates to operators/map, so it captures as well.
  • tee / teeAsync propagate directly — there is no failure state to convert.
  • toOption / fromOption never throw; fromOption needs an error value (or factory) for the None branch.
  • Throw policy: behavior-modes.md §4.4.
  • operators — the operators these adapters feed into.
  • option — Option-side operators, including okOr / transpose bridges.
  • primitives — lift, the dual-state alternative to switchFn.