Overview

Succeed

Create a behavior that always succeeds with a value.

result

Install

$
Terminal window
pnpm dlx shadcn@latest add https://archyn.net/r/succeed.json

Copy the files below into the target paths shown in each tab.

ts@lib/flow/succeed.ts
import { type Behavior } from "./core/runtime";
import { task } from "./task";
/**
* Creates a behavior that always succeeds with the same value.
*
* Use `succeed` for constant branches, tests, and pipeline defaults.
*
* @typeParam O - Output value type.
* @param value - Value returned for every execution.
* @returns A behavior that ignores input and returns `Ok`.
*
* @example
* ```ts
* const cached = succeed({ source: "cache" });
* ```
*/
export function succeed<O>(value: O): Behavior<unknown, O, never> {
return task<unknown, O, never>((_input, context) => context.ok(value));
}

Update the import paths to match your project setup.

Create a Behavior that always succeeds with a fixed value.

Usage

succeed is a small constructor for constant successful Behavior values. It is useful in tests, branches, and fallback flows.

Use it when:

  • Provide a constant branch result.
  • Stub a successful Behavior in examples or tests.
  • Return fallback data after recovery.
import { succeed } from "@/lib/flow/succeed";
const useCachedValue = succeed({ source: "cache", ready: true });

Behavior

succeed wraps the value in a task and returns context.ok(value) for every run.

succeed has no domain failure type. Runtime cancellation can still stop execution before the task body runs.

Types

The behavior has unknown input, fixed output, and no domain error.

Import from @/lib/flow/succeed.

Composition Notes

Use succeed for constant fallback branches and tests.

Do not use succeed for values that must be recomputed per input; use task.

Source

ts@lib/flow/succeed.ts
import { type Behavior } from "./core/runtime";
import { task } from "./task";
/**
* Creates a behavior that always succeeds with the same value.
*
* Use `succeed` for constant branches, tests, and pipeline defaults.
*
* @typeParam O - Output value type.
* @param value - Value returned for every execution.
* @returns A behavior that ignores input and returns `Ok`.
*
* @example
* ```ts
* const cached = succeed({ source: "cache" });
* ```
*/
export function succeed<O>(value: O): Behavior<unknown, O, never> {
return task<unknown, O, never>((_input, context) => context.ok(value));
}