rp

rocket-pipes

Powerful pipes for TypeScript, that chain Promise and ADT for you 🚌 -> ⛰️ -> 🚠 -> πŸ‚ -> πŸš€

Showing:

Popularity

Downloads/wk

8

GitHub Stars

12

Maintenance

Last Commit

6mos ago

Contributors

1

Package

Dependencies

6

Size (min+gzip)

4.6KB

License

MIT

Type Definitions

Built-In

Tree-Shakeable

No?

Categories

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

VanillaMonetPurifyfp-ts
PromiseEitherEitherEither
MaybeMaybePromise\<Either>
ValidationEitherAsync
Promise\<Either>MaybeAsync
Promise\<Maybe>Promise\<Either>
Promise\<Validation>Promise\<Maybe>
Promise\<EitherAsync>
Promise\<MaybeAsync>

Examples

Basic
const resp = await p(
  () => 123,
  (n) => n + 1
)();
expect(resp + 1).toEqual(125);
Context
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
const resp = await p(
  () => 123,
  (n) => ep(n + 1),
  (n) => "qwe"
)();
iep(resp) && expect(resp.r + 1).toEqual(125);
Replace pipeline
const fn = p(
  () => 123,
  (n) => n + 1
);
const resp = await fn.replace([[0, () => 124]])();
expect(resp + 1).toEqual(126);
AOP beforeAll/afterAll hooks
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
clearAfterAll();
clearBeforeAll();
Promise basic
const resp = await p(
  () => Promise.resolve(123),
  (n) => n + 1
)();
expect(resp + 1).toEqual(125);
Either right
const resp = await p(
  () => Either.right(123),
  (n) => n + 1
)();
expect(resp + 1).toEqual(125);
Promise can include anything supported
const resp = await p(
  () => Promise.resolve(Either.right(123)),
  (n) => n + 1
)();
expect(resp + 1).toEqual(125);
Either left
const resp = await p(
  () => Either.left(123),
  (_, l) => l + 1
)();
expect(resp + 1).toEqual(125);
Maybe some
const resp = await p(
  () => Maybe.some(123),
  (n) => n + 1
)();
expect(resp + 1).toEqual(125);
Maybe none
const resp = await p(
  () => Maybe.none(),
  (s, n) => s || n
)();
expect(resp).toEqual(void 0);
Validation success
const resp = await p(
  () => Validation.success(123),
  (n) => n + 1
)();
expect(resp + 1).toEqual(125);
Validation fail
const resp = await p(
  () => Validation.fail(123),
  (_, l) => l + 1
)();
expect(resp + 1).toEqual(125);

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100