Parallel to async waterfall
- Dominant language
- JavaScript
- Stars
- 3.4k
- Forks
- 145
- PR merge metrics
- No merged PRs in 30d
Description
Waterfall is one of the biggest uses of async, and there are some definite parallels to it in Highland:
``` javascript
var async = require('async');
var _ = require('highland');
var f1 = function(arg, callback){
callback(null, arg + 'b');
}
var f2 = function(arg, callback){
callback(null, arg + 'c');
}
var f3 = function(arg, callback) {
callback(null, arg + 'd');
}
function chain(s, f) {
return s.flatMap(_.wrapCallback(f))
}
async.waterfall([async.apply(f1, 'a'), f2, f3], function (err, arg) {
console.log(arg); // 'abcd'
});
_(['a'])
.flatMap(_.wrapCallback(f1))
.flatMap(_.wrapCallback(f2))
.flatMap(_.wrapCallback(f3))
.apply(_.log); // 'abcd'
_([f1, f2, f3])
.reduce(_(['a']), chain)
.flatten()
.apply(_.log); // 'abcd'
```
There are probably other ways to do the same thing, too.
I got to thinking about this from [this blog post](http://blog.vullum.io/javascript-flow-callback-hell-vs-async-vs-highland/) which draws parallels between async and highland, much like `nfcall` does in #171 and like was mentioned in #188.
Thoughts on an explicit `waterfall` parallel in highland? It could implement one of the patterns above, and it might also be able to support passing through multiple arguments. [Async's example](https://github.com/caolan/async#waterfall) does this, but it's a bit of a trick with highland.
Contributor guide
Research direction
No implementation file or test is identified. Compare the shown Highland flatMap/reduce patterns with async.waterfall and review related issues #171 and #188; a decision is needed on the API and multi-argument behavior before implementation can be considered done.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100