Files
native-monad/.claude/skills/native-monad/references/forbidden-patterns.md
2026-03-31 12:44:27 +02:00

2.0 KiB

Forbidden Patterns

Banned Method Names

These methods DO NOT EXIST in native-monad. Never suggest, generate, or reference them:

unwrap, unwrapOr, unwrapOrElse, expect, or, orElse, and, andThen, inspect, getOrElse, fold, contains, zip, unzip, transpose, chain, recover, tap, peek, bimap, cata, either, maybe, fromNullable, tryCatch, encase.

Anti-Pattern Examples

Value extraction

// WRONG — unwrap does not exist
const value = result.unwrap();
const value = result.unwrapOr(defaultValue);
const value = result.expect("should be ok");

// CORRECT — use match()
const value = result.match(
  (v) => v,
  (e) => defaultValue,
);

Chaining

// WRONG — orElse/andThen do not exist
const next = result.orElse((e) => ok(fallback));
const next = result.andThen((v) => ok(v + 1));

// CORRECT — use flatMap/flatMapErr
const next = result.flatMapErr((e) => ok(fallback));
const next = result.flatMap((v) => ok(v + 1));

Async return types

// WRONG — raw Promise wrapping
async function fetchUser(id: string): Promise<Result<User, Error>> { ... }
async function findItem(id: string): Promise<Option<Item>> { ... }
async function query(id: string): Promise<Query<Data, Error>> { ... }

// CORRECT — sugar types
async function fetchUser(id: string): ResultPromise<User, Error> { ... }
async function findItem(id: string): OptionPromise<Item> { ... }
async function query(id: string): QueryPromise<Data, Error> { ... }

Side-effect inspection

// WRONG — inspect/tap do not exist
result.inspect((v) => console.log(v));
option.tap((v) => log(v));

// CORRECT — use map with side effect + return, or match
const logged = result.map((v) => { console.log(v); return v; });

Nullability conversion

// WRONG — fromNullable does not exist
const opt = Option.fromNullable(maybeNull);

// CORRECT — use Option.from()
const opt = Option.from(maybeNull);