Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/darky/rocket-pipes
Powerful pipes for TypeScript, that chain Promise and ADT for you 🚌 -> ⛰️ -> 🚠 -> 🏂 -> 🚀
https://github.com/darky/rocket-pipes
adt aop chain-promise compose composition context either exit fp-libraries kleisli maybe mock monet pipe pipeline promise ramda ts typescript validation
Last synced: 3 months ago
JSON representation
Powerful pipes for TypeScript, that chain Promise and ADT for you 🚌 -> ⛰️ -> 🚠 -> 🏂 -> 🚀
- Host: GitHub
- URL: https://github.com/darky/rocket-pipes
- Owner: darky
- License: mit
- Created: 2020-06-12T20:43:05.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-06-16T14:22:27.000Z (8 months ago)
- Last Synced: 2024-11-07T21:49:57.247Z (3 months ago)
- Topics: adt, aop, chain-promise, compose, composition, context, either, exit, fp-libraries, kleisli, maybe, mock, monet, pipe, pipeline, promise, ramda, ts, typescript, validation
- Language: TypeScript
- Homepage:
- Size: 1.09 MB
- Stars: 25
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Rocket pipes
Powerful pipes for TypeScript, that chain Promise and ADT like Maybe or Either from popular FP libraries.
### Features
- 🍬 Sugar pipes. No worries about promises or ADT itself. Work with resolved values directly.
- 💡 Type inference. No worries about manual typing work. Types of resolved values inferred automatically.
- ⛓️ FP libraries friendly. Understand Catamorphism/Foldable libraries.
- 🖇️ Mix of Promise with FP library. Yes! Catamorphism/Foldable can be included in Promise.
- 📉 Context. Easy pass context through all pipes.
- 🚪 Pipeline exit (even nested exit). You can exit from any place of pipeline with result value (it's also have proper type inference 🤘)
- 🏹 Pipeline replace. You can replace function on pipeline to another on the fly. Useful for mock testing.
- ➰ AOP. Use beforeAll/afterAll hooks for your pipelines.
- 🦥 Lazy. Pipeline returns function, that can be used later. It's friendly with Ramda or Sanctuary.### Library support
| Vanilla | Monet | Purify | fp-ts | RxJS / IxJS |
|---------|-----------------------|------------------------|-------------------|-------------|
| Promise | Either | Either | Either | pipe |
| | Maybe | Maybe | Promise\ | |
| | Validation | EitherAsync | | |
| | Promise\ | MaybeAsync | | |
| | Promise\ | Promise\ | | |
| | Promise\ | Promise\ | | |
| | | Promise\ | | |
| | | Promise\ | | |*if you want slim version without libraries support, install slim version `npm install rocket-pipes-slim`*
### Examples
##### Basic
```ts
const resp = await p(
() => 123,
(n) => n + 1
)();
expect(resp + 1).toEqual(125);
```##### Context (❗ mutable)
```ts
const resp = await p(
() => 123,
pc((ctx: {n: number}) => n => n + ctx.n),
n => n + 1
).context({n: 1})();
expect(resp + 1).toEqual(126);
```##### Exit pipeline
```ts
const resp = await p(
() => 123,
(n) => ep(n + 1),
(n) => "qwe"
)();
iep(resp) && expect(resp.r + 1).toEqual(125);
```##### Replace pipeline (❗ mutable)
```ts
const fn = p(
() => 123,
(n) => n + 1
);
const resp = await fn.replace([[0, () => 124]])();
expect(resp + 1).toEqual(126);fn.replaceUndo();
expect(await fn()).toEqual(125);
```##### AOP beforeAll/afterAll hooks
```ts
beforeAll((label, n) => {
expect(label).toEqual("(n) => n + 1\n(n) => n + 1");
expect(n).toEqual(123);
});
afterAll((label, n) => {
expect(label).toEqual("(n) => n + 1\n(n) => n + 1");
expect(n).toEqual(125);
});
p(
(n: number) => n + 1,
(n) => n + 1
)(123);
```##### AOP clear hooks
```ts
clearAfterAll();
clearBeforeAll();
```##### Promise basic
```ts
const resp = await p(
() => Promise.resolve(123),
(n) => n + 1
)();
expect(resp + 1).toEqual(125);
```##### Either right
```ts
const resp = await p(
() => Either.right(123),
(n) => n + 1
)();
expect(resp + 1).toEqual(125);
```##### Promise can include anything supported
```ts
const resp = await p(
() => Promise.resolve(Either.right(123)),
(n) => n + 1
)();
expect(resp + 1).toEqual(125);
```##### Either left
```ts
const resp = await p(
() => Either.left(123),
(_, l) => l + 1
)();
expect(resp + 1).toEqual(125);
```##### Maybe some
```ts
const resp = await p(
() => Maybe.some(123),
(n) => n + 1
)();
expect(resp + 1).toEqual(125);
```##### Maybe none
```ts
const resp = await p(
() => Maybe.none(),
(s, n) => s || n
)();
expect(resp).toEqual(void 0);
```##### Validation success
```ts
const resp = await p(
() => Validation.success(123),
(n) => n + 1
)();
expect(resp + 1).toEqual(125);
```##### Validation fail
```ts
const resp = await p(
() => Validation.fail(123),
(_, l) => l + 1
)();
expect(resp + 1).toEqual(125);
```