aboutsummaryrefslogtreecommitdiff
path: root/node_modules/when/unfold/list.js
blob: 529c2c93d573ddb86e95c2e2e61b88f8fabb5975 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/** @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); });