# native-monad TypeScript monad library using native JS/TS idioms - Result, Option, and Query types. ## Install ```bash npm install native-monad ``` ## Types ### Result\ Success/failure type. Variants: `Ok` | `Err`. ```typescript import { ok, err, Result } from 'native-monad'; const success = ok(42); // Ok const failure = err('oops'); // Err success.map(x => x * 2); // Ok(84) failure.map(x => x * 2); // Err('oops') success.match( value => `got ${value}`, error => `failed: ${error}`, ); // 'got 42' // Collection operations Result.all([ok(1), ok(2), ok(3)]); // Ok([1, 2, 3]) Result.all([ok(1), err('x')]); // Err('x') ``` ### Option\ Presence/absence type. Variants: `Some` | `None`. ```typescript import { some, none, Option } from 'native-monad'; const present = some('hello'); // Some const absent = none(); // None present.map(s => s.toUpperCase()); // Some('HELLO') absent.map(s => s.toUpperCase()); // None // Create from nullable values (only null/undefined are falsy) Option.from(0); // Some(0) Option.from(null); // None Option.from(undefined); // None ``` ### Query\ Three-state monad combining Result and Option. Variants: `OkSome` | `OkNone` | `ErrNone`. ```typescript import { okSome, okNone, errNone } from 'native-monad'; const found = okSome(42); // success with value const notFound = okNone(); // success without value const failed = errNone('error'); // failure ``` ## Development ```bash pnpm install pnpm build # Build (dual ESM/CJS) pnpm test # Run Jest tests pnpm test:types # Run vitest type tests pnpm lint # ESLint pnpm typecheck # tsc --noEmit ```