{"library":"purify-ts","title":"Purify TS: Functional Programming Standard Library","description":"Purify is a TypeScript library providing a standard set of functional programming abstractions, primarily focused on Algebraic Data Types (ADTs) such as Maybe, Either, and their asynchronous counterparts. Its purpose is to enable developers to write safer, more maintainable code by handling optional values and errors explicitly. The current stable version is 2.1.4, with patch releases addressing build issues and minor fixes occurring frequently, while minor versions introduce new features. Purify distinguishes itself by offering a developer-friendly API that prioritizes practical application and ease of use over more complex theoretical constructs like Higher-Kinded Types, a deliberate design choice given TypeScript's current capabilities. It is fully type-safe, entirely written in TypeScript, and adheres to the Fantasy Land specification, aiming to seamlessly integrate robust error and optionality handling into existing TypeScript projects without requiring elaborate type definitions or runtime workarounds.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install purify-ts"],"cli":null},"imports":["import { Maybe, Just, Nothing } from 'purify-ts'","import { Either, Left, Right } from 'purify-ts'","import { MaybeAsync } from 'purify-ts'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { Maybe, Either, Just, Nothing, Left, Right } from 'purify-ts';\n\n// Example 1: Handling optional values with Maybe\nfunction getUserEmail(id: number): Maybe<string> {\n  const users = {\n    1: { name: 'Alice', email: 'alice@example.com' },\n    2: { name: 'Bob', email: undefined },\n    3: { name: 'Charlie', email: 'charlie@example.com' }\n  };\n  const user = users[id];\n  return Maybe.fromNullable(user?.email); // Safely get email, handles null/undefined\n}\n\nconsole.log(`User 1 email: ${getUserEmail(1).map(e => e.toUpperCase()).getOrElse('No email found')}`);\n// Expected: User 1 email: ALICE@EXAMPLE.COM\n\nconsole.log(`User 2 email: ${getUserEmail(2).map(e => e.toUpperCase()).getOrElse('No email found')}`);\n// Expected: User 2 email: No email found\n\nconsole.log(`User 4 email: ${getUserEmail(4).map(e => e.toUpperCase()).getOrElse('No email found')}`);\n// Expected: User 4 email: No email found\n\n// Example 2: Working with Either for success/failure\nfunction divide(a: number, b: number): Either<string, number> {\n  return b === 0 ? Left('Cannot divide by zero') : Right(a / b);\n}\n\nconst result1 = divide(10, 2);\nresult1.ifRight(val => console.log(`10 / 2 = ${val}`)); // Expected: 10 / 2 = 5\nresult1.ifLeft(err => console.error(`Error: ${err}`));\n\nconst result2 = divide(10, 0);\nresult2.ifRight(val => console.log(`10 / 0 = ${val}`));\nresult2.ifLeft(err => console.error(`Error: ${err}`)); // Expected: Error: Cannot divide by zero\n\n// Example 3: Using fromPredicate with type guards\nconst isPositive = (num: number): num is number => num > 0;\nconst maybePositive = Maybe.fromPredicate(isPositive, 5);\nconsole.log(`Is 5 positive? ${maybePositive.isJust()}`); // Expected: Is 5 positive? true\n\nconst maybeNegative = Maybe.fromPredicate(isPositive, -1);\nconsole.log(`Is -1 positive? ${maybeNegative.isJust()}`); // Expected: Is -1 positive? false","lang":"typescript","description":"This quickstart demonstrates the core usage of Purify-TS's Maybe and Either ADTs for safely handling optional values and propagating errors, respectively. It also shows `fromPredicate` for type-safe validation.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}