Comparing version 0.0.1 to 0.0.2
@@ -9,3 +9,3 @@ { | ||
}, | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"scripts": { | ||
@@ -12,0 +12,0 @@ "lint": "tslint --project ./tsconfig.json", |
# pipe-ts | ||
[What is `pipe`?](https://dev.to/benlesh/a-simple-explanation-of-functional-pipe-in-javascript-2hbj) | ||
Overloads to supports up to 9 functions. | ||
@@ -18,9 +20,10 @@ | ||
```ts | ||
const singleParamFnAdd1 = (n: number) => n + 1; | ||
const singleParamFnTimes2 = (n: number) => n * 2; | ||
const add1 = (n: number) => n + 1; | ||
const times2 = (n: number) => n * 2; | ||
const result = pipe( | ||
singleParamFnAdd1, | ||
singleParamFnTimes2, | ||
)(1); | ||
const add1ThenTimes2 = pipe( | ||
add1, | ||
times2, | ||
); | ||
const result: number = add1ThenTimes2(1); | ||
@@ -33,9 +36,10 @@ assert.strictEqual(result, 4); | ||
```ts | ||
const singleParamFnAdd1 = (n: number) => n + 1; | ||
const multipleParamFn = (a: number, b: number) => a - b; | ||
const difference = (a: number, b: number) => a - b; | ||
const add1 = (n: number) => n + 1; | ||
const result = pipe( | ||
multipleParamFn, | ||
singleParamFnAdd1, | ||
)(2, 1); | ||
const differenceThenAdd1 = pipe( | ||
difference, | ||
add1, | ||
); | ||
const result: number = differenceThenAdd1(5, 4); | ||
@@ -50,6 +54,6 @@ assert.strictEqual(result, 2); | ||
```ts | ||
const singleParamFnAdd1 = (n: number) => n + 1; | ||
const singleParamFnTimes2 = (n: number) => n * 2; | ||
const add1 = (n: number) => n + 1; | ||
const times2 = (n: number) => n * 2; | ||
const result = pipeWith(1, singleParamFnAdd1, singleParamFnTimes2); | ||
const result: number = pipeWith(1, add1, times2); | ||
@@ -56,0 +60,0 @@ assert.strictEqual(result, 4); |
@@ -7,3 +7,3 @@ "use strict"; | ||
var singleParamFnTimes2 = function (n) { return n * 2; }; | ||
var multipleParamFn = function (a, b) { return a - b; }; | ||
var multipleParamFnDifference = function (a, b) { return a - b; }; | ||
// We should really bring in a test framework to help here. | ||
@@ -31,3 +31,3 @@ var describe = function (name, fn) { | ||
it('works when first function has multiple params', function () { | ||
assert.strictEqual(index_1.pipe(multipleParamFn, singleParamFnAdd1)(2, 1), 2); | ||
assert.strictEqual(index_1.pipe(multipleParamFnDifference, singleParamFnAdd1)(5, 4), 2); | ||
}); | ||
@@ -34,0 +34,0 @@ }); |
Sorry, the diff of this file is not supported yet
13117
66