Genel bakış
functionComposition

tap

Runs a side effect after source success without changing the output.

Signature

tsSignature
export function tap<I, O, E, C extends object>(
source: Behavior<I, O, E, C>,
effect: (output: O, context: RuntimeContext<C>) => Awaitable<void>,
): Behavior<I, O, E, C>;

Imports

tsImport
import { tap } from "@/lib/flow/tap";
import { tap } from "@/lib/flow";

Type Parameters

I

Source input type.

O

Source output type.

E

Source domain error type.

C

Custom context type.

Parameters

source
Behavior<I, O, E, C>

Behavior whose successful output should be observed.

effect
(output: O, context: RuntimeContext<C>) => Awaitable<void>

Side-effect callback invoked only after source success.

Returns

A behavior with the same input, output, and domain error types.

Return type
Behavior<I, O, E, C>

Details

Source failures pass through unchanged. Thrown effect errors are captured by the underlying task

runtime as `Thrown`.

Examples

tsExample
const auditedLoad = tap(loadUser, (user) => audit("loaded", user.id));
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

Runtime error returned when user code throws.

type

Source

tsflow/tap.ts:25-36
export function tap<I, O, E, C extends object>(
source: Behavior<I, O, E, C>,
effect: (output: O, context: RuntimeContext<C>) => Awaitable<void>,
): Behavior<I, O, E, C> {
return pipe(
source,
task<O, O, never, C>(async (output, context) => {
await effect(output, context);
return context.ok(output);
}),
);
}