Registry / serialization / fp-ts-contrib

fp-ts-contrib

JSON →
library0.1.29jsnpmunverified

fp-ts-contrib is a community-driven utility package designed to extend the core functionalities of `fp-ts`, a popular TypeScript library for functional programming. It provides additional data types, combinators, and instances for existing types that are not part of the `fp-ts` core but are frequently requested or useful in a functional programming context. Currently at version 0.1.29, the library exhibits a consistent release cadence with new features and bug fixes, as seen in the frequent micro-version bumps. Its key differentiator is providing a shared space for useful `fp-ts` extensions, reducing boilerplate and fostering a more robust functional ecosystem by incorporating patterns like `IOOption`, `ReaderIO`, and `Zipper`, which are not directly in `fp-ts` itself. It primarily targets TypeScript environments and maintains compatibility with `fp-ts` via peer dependencies.

npm install fp-ts-contrib
INSTALL
IMPORT
SIG · FP-TS-CONTRIB
F
fp-ts-contrib
serializationjavascriptv0.1.29
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

IOOption
import * as IOOption from 'fp-ts-contrib/IOOption'
import { IOOption } from 'fp-ts-contrib'
Many modules within `fp-ts-contrib` are exposed as default exports of their respective paths, often imported as a namespace.
ReaderIO
import * as ReaderIO from 'fp-ts-contrib/ReaderIO'
const ReaderIO = require('fp-ts-contrib/ReaderIO');
The library is primarily designed for ESM imports with TypeScript. While CommonJS might work, it's not the idiomatic usage.
Zipper
import * as Zipper from 'fp-ts-contrib/Zipper'
Import specific modules from their direct path to avoid bundling unnecessary code. Types are bundled with the package.

Demonstrates the use of `IOOption` to handle potentially absent input within an `IO` context, processing it if present.

import * as IOOption from 'fp-ts-contrib/IOOption'; import * as O from 'fp-ts/Option'; import * as IO from 'fp-ts/IO'; import { pipe } from 'fp-ts/function'; // Example using IOOption: an IO that might produce an Option const getUserInput = (prompt: string): IO.IO<O.Option<string>> => IO.of(() => { const input = 'some user value'; // In a real app, this would be `prompt()` or similar return input ? O.some(input) : O.none; }); const processInput = (input: string): IO.IO<number> => IO.of(() => input.length); const mainIOOption = pipe( getUserInput('Enter a value:'), IOOption.chainIOK((input: string) => processInput(input)), IOOption.map((length: number) => `Processed length: ${length}`), IOOption.getOrElse(() => IO.of('No input provided.')), ); // Execute the IO to see the result const result = mainIOOption(); console.log(result());
Debug
Known issues
gotchaStarting from version 0.1.0, `fp-ts-contrib` transitioned to using `fp-ts` as a `peerDependency`. This means `fp-ts` must be manually installed in your project, it will not be installed automatically.
fix
Ensure `fp-ts` is explicitly installed in your project: `npm install fp-ts` or `yarn add fp-ts`.
affects: >=0.1.0
gotchaThe package exposes its modules via specific paths (e.g., `fp-ts-contrib/IOOption`). Importing directly from `fp-ts-contrib` as a named import (e.g., `import { IOOption } from 'fp-ts-contrib'`) might lead to undefined symbols or larger bundle sizes due to incorrect tree-shaking.
fix
Always import modules directly from their path, e.g., `import * as IOOption from 'fp-ts-contrib/IOOption'`.
affects: >=0.1.0
gotchaTypeScript compatibility requires a minimum version of TypeScript 3.5+ for `fp-ts-contrib` versions 0.1.x and above. Using older TypeScript versions may lead to compilation errors.
fix
Upgrade your TypeScript version to 3.5 or newer: `npm install typescript@^3.5` or `yarn add typescript@^3.5`.
affects: >=0.1.0
Errors
Common errors & fixes
Error: Cannot find module 'fp-ts' or its corresponding type declarations.
`fp-ts` is a peer dependency and was not installed in the project.
fix
Install `fp-ts` manually: `npm install fp-ts` or `yarn add fp-ts`.
TS2307: Cannot find module 'fp-ts-contrib' or its corresponding type declarations.
Incorrect import path or `fp-ts-contrib` not installed.
fix
Ensure `fp-ts-contrib` is installed (`npm i fp-ts-contrib`) and check import paths. Also verify your `tsconfig.json` includes `node_modules` in its types.
TS2305: Module '"fp-ts-contrib"' has no exported member 'IOOption'.
Attempting to named import a module that is exposed as a default export from a subpath.
fix
Import the module from its direct path as a namespace: `import * as IOOption from 'fp-ts-contrib/IOOption'`.
Upgrade
Version history
0.1.29latest on npm
Audit
Dependencies
fp-tsrequiredCore functional programming utilities extended by this library; listed as a peer dependency.
Agent activity
2 hits · last 30 days
node
2
Resources
fp-ts-contrib — npm install fp-ts-contrib · libregistry