> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cbrock.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# ts-chas

> A functional programming and utility library for TypeScript. Type-safe error handling, runtime validation, lazy async tasks, and composable pipelines all in one cohesive ecosystem.

`ts-chas` gives you the building blocks for writing TypeScript that is explicit about errors, safe at runtime, and easy to compose. Instead of scattered `try/catch` blocks and `null` checks, you get a suite of tightly integrated modules: `Result`, `Guard`, `Task`, `Option`, `TaggedErrors`, and `Pipe/Flow` that work nicely together.

<CardGroup cols={2}>
  <Card title="Installation" icon="box" href="/installation">
    Add ts-chas to your project in under a minute.
  </Card>

  <Card title="Quick Start" icon="rocket" href="/quickstart">
    See the key patterns with working examples.
  </Card>

  <Card title="Core Concepts" icon="book" href="/concepts/result">
    Understand Result, Guard, Task, and more.
  </Card>

  <Card title="API Reference" icon="code" href="/api/result/overview">
    Browse the full public API surface.
  </Card>
</CardGroup>

## What's inside

<CardGroup cols={2}>
  <Card title="Result & ResultAsync" icon="circle-check" href="/concepts/result">
    Replace `try/catch` with explicit, type-safe `Result<T, E>` and `ResultAsync<T, E>` that carry error types in the signature.
  </Card>

  <Card title="Guard" icon="shield" href="/concepts/guard">
    Chainable runtime type validators that double as TypeScript type predicates, with built-in schema parsing and Standard Schema v1 support.
  </Card>

  <Card title="Task" icon="bolt" href="/concepts/task">
    Lazy async pipelines with retries, timeouts, circuit breakers, throttling, and caching; all composable and cancellable.
  </Card>

  <Card title="Tagged Errors" icon="tag" href="/concepts/tagged-errors">
    Discriminated error unions built on native `Error` objects, enabling exhaustive pattern matching across your call stack.
  </Card>

  <Card title="Option" icon="circle-question" href="/concepts/option">
    Model the presence or absence of a value explicitly, with the same rich API as `Result`.
  </Card>

  <Card title="Pipe & Flow" icon="arrow-right-arrow-left" href="/concepts/pipe-flow">
    Compose functions into readable, reusable data pipelines with full TypeScript type inference.
  </Card>
</CardGroup>

## Get started

<Steps>
  <Step title="Install the package">
    ```bash theme={null}
    npm install ts-chas
    ```
  </Step>

  <Step title="Import the modules you need">
    ```typescript theme={null}
    import { chas } from 'ts-chas';             // everything
    import { is } from 'ts-chas/guard';          // guard only
    import { Task } from 'ts-chas/task';         // task only
    ```
  </Step>

  <Step title="Replace your first try/catch">
    ```typescript theme={null}
    import { chas } from 'ts-chas';

    const result = await chas.fromPromise(
      fetch('/api/user').then(r => r.json()),
      (e) => `Fetch failed: ${e}`
    );

    if (result.isOk()) {
      console.log(result.value);
    }
    ```
  </Step>

  <Step title="Explore the concepts">
    Read through [Core Concepts](/concepts/result) to understand how the modules fit together, or jump straight to a [Quick Start example](/quickstart).
  </Step>
</Steps>
