Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@adam-rocska/invertible

adam-rocska26MIT1.1.3TypeScript support: included

A library for creating and managing invertible functions and type-safe pipelines in TypeScript.

invertible, pipeline, pure, functional, functional programming, functional programming library, inverse, proverse, typescript, strict, type-safe, type safety, stateless, composition

readme

Invertible Functions for TS & JS

NPM Version License

Aspect Badge
Minified Minified
Minified + gzip Minified + gzip
Dependency Count Dependency Count
Tree-shaking Support Tree-shaking Support

A library for creating and managing invertible functions and type-safe pipelines in TypeScript.

Installation

To install the package, use npm or yarn:

npm install @adam-rocska/invertible

or

pnpm add @adam-rocska/invertible

Usage

Simple example:

import {Invertible} from "@adam-rocska/invertible";
import {pipe} from "@adam-rocska/invertible/pipe";

test(`Simple arithmetics example`, async () => {
  const increment = Invertible(
    async (a: number) => a + 1,
    async (a: number) => a - 1
  );
  const double = Invertible(
    async (a: number) => a * 2,
    async (a: number) => a / 2
  );

  expect(await increment(1)).toBe(2);
  expect(await increment.inverse(2)).toBe(1);

  expect(await double(2)).toBe(4);
  expect(await double.inverse(4)).toBe(2);

  const pipeExample = pipe(increment)
    .pipe(double)
    .pipe(increment)
    .pipe(double);

  expect(await pipeExample(1)).toBe(10);
});

Usefulness Ideas

  1. Undo-able user interface actions
  2. Reversible CI pipeline steps and pipelines
  3. Bidirectional data coding

Contributing

Contributions are welcome! Please read the contributing guidelines before submitting a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Ádám László Rocska