Overview
functionComposition

map

Maps the successful output of a behavior.

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

I

Source input type.

O

Source output type.

D

Projected output type.

E

Source domain error type.

C

Custom context type.

Parameters

source
Behavior<I, O, E, C>

Behavior whose success value should be transformed.

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);
Awaitable

Represents a value that may be returned directly or through a Promise.

type
Behavior

Executable Flow workflow unit.

type
task

Creates a typed behavior from synchronous or asynchronous application code.

function
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)),
),
);
}