Idea for discussion: forkBy
- Dominant language
- JavaScript
- Stars
- 3.4k
- Forks
- 145
- PR merge metrics
- No merged PRs in 30d
Description
I often find myself in the situation where I want to do the inverse of merge, i.e. split the values of a stream into two different streams. I might be missing some obvious functionality, but this is how I do it today - is there a sleeker way?
``` javascript
let forkBy = (strm, evaluator) => {
let a = _(), b = _()
_(strm).each(x => evaluator(x) ? a.write(x) : b.write(x))
return [a, b]
}
```
Example usage
``` javascript
let isSpecial = str => !!str.match(/^specialcasething/)
let [ specialThings, otherThings ] = forkBy(connectionStream, isSpecial)
```
Is this a pattern you recognize in your coding?
Contributor guide
Research direction
Start with the proposed forkBy entry point and compare it with Highland's existing stream operators, especially merge-related functionality. Review the discussion to determine whether a two-output operator is wanted and what its public API and behavior should be; done requires an agreed design before implementation.
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