neverthrow Result and ResultAsync pipelines: working versions (tested 2026-10-15)
Model fallible sync and async flows with neverthrow Result and ResultAsync, mapping domain errors through andThen and combinators without throwing.
passed1 passed · 0 failed2026-10-15 16:02 UTC- Status
- passed
- Last passed
- 2026-10-15 16:02 UTC
- Tests
- 1 / 1
- Language
- TypeScript
- Runtime
- node v22.23.3
pinned versions3
neverthrow@8.2.0@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false npm test
test environment
node v22.23.3 linux 6.17.0-1022-azure x64 runner: github-actions 38764699834
The code
Exactly the files that passed. Your agent can pull them with get_recipe("neverthrow-async-result") (install), or see them on GitHub.
package.json
{
"name": "neverthrow-async-result",
"private": true,
"type": "module",
"scripts": {
"test": "node --import tsx --test test/*.test.ts"
},
"dependencies": {
"neverthrow": "8.2.0"
},
"devDependencies": {
"@types/node": "26.6.5",
"tsx": "4.23.15"
}
}
src/payments.ts
import { err, ok, Result, ResultAsync } from "neverthrow";
export class NotFoundError extends Error {
readonly _tag = "NotFoundError" as const;
constructor(readonly id: string) { super(`not found: ${id}`); }
}
export class InsufficientFunds extends Error {
readonly _tag = "InsufficientFunds" as const;
constructor(readonly balance: number, readonly amount: number) {
super(`need ${amount}, have ${balance}`);
}
}
type Account = { id: string; balance: number };
const db = new Map<string, Account>();
export function reset(seed: Account[] = []) {
db.clear();
for (const a of seed) db.set(a.id, { ...a });
}
export function getAccount(id: string): Result<Account, NotFoundError> {
const a = db.get(id);
return a ? ok({ ...a }) : err(new NotFoundError(id));
}
export function charge(id: string, amount: number): Result<Account, NotFoundError | InsufficientFunds> {
return getAccount(id).andThen((a) => {
if (a.balance < amount) return err(new InsufficientFunds(a.balance, amount));
const next = { ...a, balance: a.balance - amount };
db.set(id, next);
return ok(next);
});
}
export function chargeAsync(id: string, amount: number) {
return ResultAsync.fromSafePromise(Promise.resolve(charge(id, amount))).andThen((r) => r);
}
test/payments.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import { charge, chargeAsync, getAccount, reset } from "../src/payments.ts";
test("charge success and errors", async () => {
reset([{ id: "a1", balance: 100 }]);
assert.equal(getAccount("missing").isErr(), true);
const ok = charge("a1", 40);
assert.equal(ok.isOk(), true);
if (ok.isOk()) assert.equal(ok.value.balance, 60);
const poor = charge("a1", 1000);
assert.equal(poor.isErr(), true);
if (poor.isErr()) assert.equal(poor.error._tag, "InsufficientFunds");
const asyncOk = await chargeAsync("a1", 10);
assert.equal(asyncOk.isOk(), true);
});
Connect to ProvenPin
Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.
terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp
~/.cursor/mcp.json
{ "mcpServers": { "provenpin": { "url": "https://mcp.provenpin.com/mcp" } } }.vscode/mcp.json
{ "servers": { "provenpin": { "type": "http", "url": "https://mcp.provenpin.com/mcp" } } }~/.codeium/windsurf/mcp_config.json
{ "mcpServers": { "provenpin": { "serverUrl": "https://mcp.provenpin.com/mcp" } } }MCP settings
{ "mcpServers": { "provenpin": { "type": "streamableHttp", "url": "https://mcp.provenpin.com/mcp" } } }Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.