request-compose
request-compose copied to clipboard
Wow, What an amazing package!
The idea is almost same with mine. Since that the request.js package is difficult to maintain and extend. Wow, I should consider the module in my next refactor of crawler. Years ago I published my distributed crawler framework based on middleware called floodesh, and these years I've been thinking about how to construct the single-node version of crawler, the most import idea is composable like my design in floodesh, which is also inspired by koa compose. Glad to see this, I'm watching the great work.
Thanks @mike442144, I really appreciate it!
The middleware approach is very powerful indeed. The idea here is that you have a simple compose function that calls each one of it's arguments and pass the result to the next one. The best part is that you can continue applying the same compose function over and over again on every subsequent layer on top of the client.
This approach also implies that there is no state, beyond the current request. All functions in the chain return a Promise, meaning that all errors are catched too.
In the Functional Paradigm, and in the programming languages that supports this natively, it's also known as pipe operator |> There is really no difference between the compose function that this module exposes, and the pipe operator, except syntactical.
I wrote a short article about the module here: https://dev.to/simov/composable-http-client-for-nodejs-83f
Yep, the Functional way is cool! I noticed your signature which seems like lisp? I'm now practicing FP use ramda and ramda-fantasy in my projects after reading some Haskell materials. It really empowers the code expressiveness. Thanks to your high quality article.
Yeah, I really do see similarities between Scheme (that is a Lisp) and JavaScript. Plus, the two main ingredients in JavaScript comes from:
- Scheme (the FP part, Lisp)
- Self (the prototypical OOP, Smalltalk)
I have another article where I experimented with the limits of what is possible with the JS syntax: https://dev.to/simov/anonymous-recursion-in-javascript
If you put the two examples side by side you'll notice that only the syntax differs. The underlying features such as Lexical Scope and First Class Functions work identically.
I'm not familiar with Scheme, but I tried the example in your article, I'm really surprised! I had no idea how to do anonymous recursion before, even an assignment like this:
const fn = (n) => n==0 ? 0 : fn(n-1)+fn(n-2);
I got error fn is not defined. Your article inspired me! I'll try it out. Thank you so much!!!