1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-12-23 16:13:18 +00:00
musix-oss/node_modules/when/unfold/list.js

33 lines
987 B
JavaScript
Raw Normal View History

2020-03-03 20:30:50 +00:00
/** @license MIT License (c) copyright B Cavalier & J Hann */
(function(define) {
define(function(require) {
var unfold = require('../when').unfold;
/**
* @deprecated
* Given a seed and generator, produces an Array. Effectively the
* dual (opposite) of when.reduce()
* @param {function} generator function that generates a value (or promise
* for a value) to be placed in the resulting array
* @param {function} condition given a seed, must return truthy if the unfold
* should continue, or falsey if it should terminate
* @param {*|Promise} seed any value or promise
* @return {Promise} resulting array
*/
return function list(generator, condition, seed) {
var result = [];
return unfold(generator, condition, append, seed)['yield'](result);
function append(value, newSeed) {
result.push(value);
return newSeed;
}
};
});
})(typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); });