Comparing version 4.0.0 to 5.0.0
@@ -0,3 +1,42 @@ | ||
# V5 | ||
`righto.reduce` is now more reasonable, and will now always treat the first parameter as an array of values/eventuals, rather than assuming they were functions to be called with righto. Migration is trivial: | ||
## Old style: | ||
```javascript | ||
function a(callback){ | ||
callback(null, 1); | ||
} | ||
function b(callback){ | ||
callback(null, 2); | ||
} | ||
// Old style: | ||
var result = righto.reduce([a, b]); | ||
// New style: wrap the tasks as eventuals: | ||
var result = righto.reduce([righto(a), righto(b)]); | ||
``` | ||
if you need to pass values to each task, use a custom reducer: | ||
## Old style: | ||
```javascript | ||
function a(lastResult, callback){ | ||
callback(null, lastResult + 1); | ||
} | ||
function b(lastResult, callback){ | ||
callback(null, lastResult + 2); | ||
} | ||
// Old style: | ||
var result = righto.reduce([a, b]); | ||
// New style: a reducer that passes the result into the next function: | ||
var result = righto.reduce([a, b], (result, next) => righto(next, result)); | ||
``` | ||
# V4 | ||
`righto.from` is now more reasonable, and will always either return a righto passed to it, or return a righto that resolves that value passed. | ||
@@ -4,0 +43,0 @@ This means it can no longer be used to call promise-returning functions, but that is already available with `righto.sync` |
@@ -446,3 +446,3 @@ var abbott = require('abbott'); | ||
if(!hasSeed){ | ||
seed = righto(values.shift()); | ||
seed = values.shift(); | ||
} | ||
@@ -449,0 +449,0 @@ |
{ | ||
"name": "righto", | ||
"version": "4.0.0", | ||
"version": "5.0.0", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "directories": { |
@@ -257,3 +257,3 @@ # Righto | ||
righto.reduce takes N tasks, or an Array of tasks as the first argument, | ||
righto.reduce takes an Array of values (an an eventual that resolves to an array) as the first argument, | ||
resolves them from left-to-right, optionally passing the result of the last, and the next task to a reducer. | ||
@@ -280,3 +280,3 @@ | ||
var result = righto.reduce([a, b]); | ||
var result = righto.reduce([righto(a), righto(b)]); | ||
@@ -283,0 +283,0 @@ result(function(error, finalResult){ |
@@ -350,26 +350,2 @@ var test = require('tape'), | ||
test('righto.reduce', function(t){ | ||
t.plan(4); | ||
var aCalled; | ||
function a(callback){ | ||
aCalled = true; | ||
t.pass('a called'); | ||
callback(null, 1); | ||
} | ||
function b(callback){ | ||
t.ok(aCalled, 'b called after a'); | ||
callback(null, 2); | ||
} | ||
var result = righto.reduce([a, b]); | ||
result(function(error, finalResult){ | ||
t.notOk(error, 'no error'); | ||
t.equal(finalResult, 2, 'Got correct final result'); | ||
}); | ||
}); | ||
test('righto.reduce eventuals', function(t){ | ||
@@ -438,2 +414,15 @@ t.plan(4); | ||
test('righto.reduce with values custom reducer no seed', function(t){ | ||
t.plan(2); | ||
var result = righto.reduce([1, 2, 3], function(result, next){ | ||
return righto.sync((a) => a + next, result); | ||
}); | ||
result(function(error, finalResult){ | ||
t.notOk(error, 'no error'); | ||
t.deepEqual(finalResult, 6, 'Got correct final result'); | ||
}); | ||
}); | ||
test('righto.reduce no items', function(t){ | ||
@@ -440,0 +429,0 @@ t.plan(2); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
71951
1813