caolan / caolan/highland

Custom operators

Open
#269 14 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
3.4k
Forks
145
PR merge metrics
No merged PRs in 30d

Description

RxJS [allows](https://github.com/ReactiveX/RxJava/wiki/Implementing-Your-Own-Operators) to implement your own custom operators.

What about Highland? I don't see any documentation on this. Is it conventional? If not, why?
Working with complex data like Vinyl objects in Gulp streams it would be great to have such option.

Example case, a lot of boilerplate and repeating code:

``` javascript
// === Gulp is globbing over JSON files ===
...
// Update some field in JSON
.map(file => {
let json = file.contents.toString();
let js = JSON.parse(json);
// update obj here...
let str = JSON.stringify(obj, null, 2);
file.contents = new Buffer(str);
return file;
})
...
// Filter over another field in JSON
.filter(file => {
let json = file.contents.toString(); // this mess again ^_^
let js = JSON.parse(json);
// evaluate cond here...
return cond;
})
```

Data is too complex above and operators are weak. It probably may be like this:

``` javascript
// === Gulp is globbing over JSON files ===
...
.pipe(Highland())
.asObject()
// Update some field in JSON
.map(obj => {
// update obj here...
return obj;
})
...
// Filter over another field in JSON
.filter(obj => {
// evaluate cond here...
return cond;
})
.asVinyl()
```

So I basically add `asObject` and `asVinyl` operators which convert Vinyl object with JSON content into JS object and vice versa and use existing operators like `map` and `filter` in their full power.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing Highland's existing operator API around map and filter, then compare the proposed asObject/asVinyl conversions with the Vinyl and JSON example. Define the intended custom-operator behavior and what would count as done; the issue names no files or tests, so repository exploration is required.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api, stream-processing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.