standard-data-structures
Version:
A collection of standard data-structures for node and browser
43 lines (42 loc) • 918 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Pipeline that can take only one argument.
*/
class Pipeline1 {
constructor(drain) {
this.drain = drain;
}
/**
* Refer [[Into.into]]
*/
into(F) {
return new Pipeline1(F(this.drain));
}
}
/**
* Pipeline class that takes in any number of arguments
*/
class PipelineN {
constructor(TT) {
this.TT = TT;
}
/**
* Refer [[Into.into]]
*/
into(F) {
return new Pipeline1(F(...this.TT));
}
}
/**
* Takes in any number of values that can be piped into a function.
* Returns a pipeline that can be used recursively to pipe to other functions.
*
* **Example:**
* ```ts
* import {pipe} from 'standard-data-structures'
*
* pipe(1, 2).into((A, B) => A + B).into(A => [A, A * A]).drain // [3, 9]
* ```
*/
exports.pipe = (...T) => new PipelineN(T);