Signature
tsSignature
export function map<I, O, D, E, C extends object>( source: Behavior<I, O, E, C>, project: (output: O, context: RuntimeContext<C>) => Awaitable<D>,): Behavior<I, D, E, C>;Imports
tsImport
import { map } from "@/lib/flow/map";import { map } from "@/lib/flow";Type Parameters
ISource input type.
OSource output type.
DProjected output type.
ESource domain error type.
CCustom context type.
Parameters
project(output: O, context: RuntimeContext<C>) => Awaitable<D>
Projection callback invoked only after source success.
Returns
A behavior with mapped output and the same domain error type.
Return type
Behavior<I, D, E, C>Details
Source failures pass through unchanged. The projection can be synchronous or asynchronous, and
thrown projection errors are captured by the underlying task runtime.
Examples
tsExample
const loadName = map(loadUser, (user) => user.name);Related Symbols
Awaitable
Represents a value that may be returned directly or through a Promise.
type
Behavior
Executable Flow workflow unit.
type
RuntimeContext
Execution context passed to every behavior.
type
thrown
Re-exports core result helpers used by advanced record internals.
re-export
Source
tsflow/map.ts:26-36
export function map<I, O, D, E, C extends object>( source: Behavior<I, O, E, C>, project: (output: O, context: RuntimeContext<C>) => Awaitable<D>,): Behavior<I, D, E, C> { return pipe( source, task<O, D, never, C>(async (output, taskContext) => taskContext.ok(await project(output, taskContext)), ), );}