Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Powerful pipes for TypeScript, that chain Promise and ADT for you 🚌 -> ⛰️ -> 🚠 -> 🏂 -> 🚀

License

NotificationsYou must be signed in to change notification settings

darky/rocket-pipes

Repository files navigation

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-tsRxJS / IxJS
PromiseEitherEitherEitherpipe
MaybeMaybePromise<Either>
ValidationEitherAsync
Promise<Either>MaybeAsync
Promise<Maybe>Promise<Either>
Promise<Validation>Promise<Maybe>
Promise<EitherAsync>
Promise<MaybeAsync>

if you want slim version without libraries support, install slim versionnpm install rocket-pipes-slim

Examples

Basic
constresp=awaitp(()=>123,(n)=>n+1)();expect(resp+1).toEqual(125);
Context (❗ mutable)
constresp=awaitp(()=>123,pc((ctx:{n:number})=>n=>n+ctx.n),n=>n+1).context({n:1})();expect(resp+1).toEqual(126);
Exit pipeline
constresp=awaitp(()=>123,(n)=>ep(n+1),(n)=>"qwe")();iep(resp)&&expect(resp.r+1).toEqual(125);
Replace pipeline (❗ mutable)
constfn=p(()=>123,(n)=>n+1);constresp=awaitfn.replace([[0,()=>124]])();expect(resp+1).toEqual(126);fn.replaceUndo();expect(awaitfn()).toEqual(125);
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
constresp=awaitp(()=>Promise.resolve(123),(n)=>n+1)();expect(resp+1).toEqual(125);
Either right
constresp=awaitp(()=>Either.right(123),(n)=>n+1)();expect(resp+1).toEqual(125);
Promise can include anything supported
constresp=awaitp(()=>Promise.resolve(Either.right(123)),(n)=>n+1)();expect(resp+1).toEqual(125);
Either left
constresp=awaitp(()=>Either.left(123),(_,l)=>l+1)();expect(resp+1).toEqual(125);
Maybe some
constresp=awaitp(()=>Maybe.some(123),(n)=>n+1)();expect(resp+1).toEqual(125);
Maybe none
constresp=awaitp(()=>Maybe.none(),(s,n)=>s||n)();expect(resp).toEqual(void0);
Validation success
constresp=awaitp(()=>Validation.success(123),(n)=>n+1)();expect(resp+1).toEqual(125);
Validation fail
constresp=awaitp(()=>Validation.fail(123),(_,l)=>l+1)();expect(resp+1).toEqual(125);

About

Powerful pipes for TypeScript, that chain Promise and ADT for you 🚌 -> ⛰️ -> 🚠 -> 🏂 -> 🚀

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp