machinepack-arrays
Advanced tools
Comparing version 3.0.1 to 3.0.2
@@ -25,8 +25,14 @@ module.exports = { | ||
item: { | ||
friendlyName: 'Current item', | ||
description: 'The current item in the array.', | ||
itemOf: 'array' // same type as the items of the `array` input of the calling machine | ||
}, | ||
index: { | ||
friendlyName: 'Current index', | ||
description: 'The index of the current item in the array.', | ||
example: 3 | ||
}, | ||
lastIndex: { | ||
friendlyName: 'Last index', | ||
description: 'The index of the last item in the array.', | ||
example: 3 | ||
@@ -36,5 +42,14 @@ } | ||
expects: { | ||
error: {}, | ||
halt: {}, | ||
success: {} | ||
error: { | ||
friendlyName: 'break with error', | ||
description: 'Something went wrong- stop iterating and skip over all remaining items.' | ||
}, | ||
halt: { | ||
friendlyName: 'break', | ||
description: 'Everything is ok, but stop iterating and skip over all remaining items.' | ||
}, | ||
success: { | ||
friendlyName: 'next item', | ||
description: 'Continue to next item, or if there are no more items, stop.' | ||
} | ||
}, | ||
@@ -102,3 +117,3 @@ }, | ||
// the entire operation a failure, including all iterations | ||
// so far. `reduce` will call its error exit.) | ||
// so far. `each` will call its error exit.) | ||
error: function (err){ | ||
@@ -111,3 +126,3 @@ return next(err); | ||
// iterations; but that past iterations are ok. | ||
// `reduce` will call its success exit) | ||
// `each` will call its success exit) | ||
halt: function (){ | ||
@@ -114,0 +129,0 @@ haltEarly = true; |
@@ -32,8 +32,14 @@ module.exports = { | ||
item: { | ||
friendlyName: 'Current item', | ||
description: 'The current item in the array.', | ||
itemOf: 'array' // same type as the items of the `array` input of the calling machine | ||
}, | ||
index: { | ||
friendlyName: 'Current index', | ||
description: 'The index of the current item in the array.', | ||
example: 3 | ||
}, | ||
lastIndex: { | ||
friendlyName: 'Last index', | ||
description: 'The index of the last item in the array.', | ||
example: 3 | ||
@@ -43,5 +49,9 @@ } | ||
expects: { | ||
error: {}, | ||
halt: {}, | ||
error: { | ||
friendlyName: 'break with error', | ||
description: 'Something went wrong- stop iterating and skip over all remaining items.' | ||
}, | ||
success: { | ||
friendlyName: 'next item', | ||
description: 'Continue to next item, or if there are no more items, stop.', | ||
like: 'itemExample' | ||
@@ -83,6 +93,2 @@ } | ||
// `haltEarly` is a flag which is used in the iterations | ||
// below to indicate that all future iterations should be skipped. | ||
var haltEarly = false; | ||
// `numIterationsStarted` will track the number of iterations | ||
@@ -99,8 +105,2 @@ // which have been at least started being processed by the iteratee. | ||
// If the `each` loop has already been halted, just skip | ||
// this iteration (which effectively means skipping all future iterations) | ||
if (haltEarly) { | ||
return next(); | ||
} | ||
// Execute iteratee machine using generic input configuration | ||
@@ -116,3 +116,3 @@ inputs.iteratee({ | ||
// the entire operation a failure, including all iterations | ||
// so far. `reduce` will call its error exit.) | ||
// so far. `map` will call its error exit.) | ||
error: function (err){ | ||
@@ -122,11 +122,2 @@ return next(err); | ||
// Halt exit | ||
// (implies that we should stop, performing no further | ||
// iterations; but that past iterations are ok. | ||
// `reduce` will call its success exit) | ||
halt: function (){ | ||
haltEarly = true; | ||
return next(); | ||
}, | ||
// Default (success) exit | ||
@@ -133,0 +124,0 @@ // (implies that we should continue iterating) |
@@ -28,11 +28,19 @@ module.exports = { | ||
item: { | ||
friendlyName: 'Current item', | ||
description: 'The current item in the array.', | ||
itemOf: 'array' // same type as the items of the `array` input of the calling machine | ||
}, | ||
index: { | ||
friendlyName: 'Current index', | ||
description: 'The index of the current item in the array.', | ||
example: 3 | ||
}, | ||
lastIndex: { | ||
friendlyName: 'Last index', | ||
description: 'The index of the last item in the array.', | ||
example: 3 | ||
}, | ||
resultSoFar: { | ||
friendlyName: 'Result so far', | ||
description: 'The result which has been accumulated so far', | ||
like: 'resultExample' // same type as the `resultExample` input of the calling machine | ||
@@ -42,7 +50,15 @@ }, | ||
expects: { | ||
error: {}, | ||
halt: {}, | ||
error: { | ||
friendlyName: 'break with error', | ||
description: 'Something went wrong- stop iterating and skip over all remaining items.' | ||
}, | ||
halt: { | ||
friendlyName: 'break', | ||
description: 'Everything is ok, but stop iterating and skip over all remaining items.' | ||
}, | ||
success: { | ||
friendlyName: 'next item', | ||
description: 'Continue to next item, or if there are no more items, stop.', | ||
like: 'resultExample' // same type as the `resultExample` input of the calling machine | ||
}, | ||
} | ||
}, | ||
@@ -49,0 +65,0 @@ }, |
{ | ||
"name": "machinepack-arrays", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "Work with arrays.", | ||
@@ -38,3 +38,2 @@ "scripts": { | ||
"sort-numbers", | ||
"sort-dictionaries", | ||
"uniq", | ||
@@ -48,3 +47,4 @@ "sample", | ||
"each", | ||
"map" | ||
"map", | ||
"sort-by" | ||
], | ||
@@ -51,0 +51,0 @@ "testsUrl": "https://travis-ci.org/" |
@@ -39,4 +39,30 @@ { | ||
] | ||
}, | ||
{ | ||
"using": { | ||
"array": "[10,20,30]", | ||
"itemExample": "1", | ||
"iteratee": "return exits.success(inputs.item+inputs.index);" | ||
}, | ||
"outcome": "success", | ||
"returns": [ | ||
"10", | ||
"21", | ||
"32" | ||
] | ||
}, | ||
{ | ||
"using": { | ||
"array": "[10,20,30]", | ||
"itemExample": "1", | ||
"iteratee": "return exits.success(inputs.item+inputs.index);" | ||
}, | ||
"outcome": "success", | ||
"returns": [ | ||
"10", | ||
"21", | ||
"32" | ||
] | ||
} | ||
] | ||
} |
53143
1905