https://github.com/adam-rocska/invertible-typescript
A library for creating and managing invertible functions and type-safe pipelines in TypeScript.
https://github.com/adam-rocska/invertible-typescript
composition compositionality functional functional-programming inverse invertible pipe pipeline proverse pure stateless strict typesafe typescript
Last synced: 7 months ago
JSON representation
A library for creating and managing invertible functions and type-safe pipelines in TypeScript.
- Host: GitHub
- URL: https://github.com/adam-rocska/invertible-typescript
- Owner: adam-rocska
- License: mit
- Created: 2023-08-30T13:16:33.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2025-04-01T21:16:19.000Z (8 months ago)
- Last Synced: 2025-04-03T10:44:35.000Z (8 months ago)
- Topics: composition, compositionality, functional, functional-programming, inverse, invertible, pipe, pipeline, proverse, pure, stateless, strict, typesafe, typescript
- Language: TypeScript
- Homepage:
- Size: 924 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Invertible Functions for TS & JS
[](https://www.npmjs.com/package/@adam-rocska/invertible)
[](https://github.com/adam-rocska/invertible-typescript/blob/master/LICENSE)
| Aspect | Badge |
| -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Minified | [](https://bundlephobia.com/package/@adam-rocska/invertible) |
| Minified + gzip | [](https://bundlephobia.com/package/@adam-rocska/invertible) |
| Dependency Count | [](https://bundlephobia.com/package/@adam-rocska/invertible) |
| Tree-shaking Support | [](https://bundlephobia.com/package/@adam-rocska/invertible) |
A library for creating and managing invertible functions and type-safe pipelines in TypeScript.
## Installation
To install the package, use npm or yarn:
```zsh
npm install @adam-rocska/invertible
```
or
```zsh
pnpm add @adam-rocska/invertible
```
## Usage
Simple example:
```ts
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](./CONTRIBUTING.md)
before submitting a pull request.
## License
This project is licensed under the MIT License - see the
[LICENSE](./LICENSE) file for details.
## Author
[Ádám László Rocska](https://github.com/adam-rocska)