UNPKG

prray

Version:

'Promisified' Array, comes with async method supports(such as mapAsync). And it is compatible with normal array.

49 lines (48 loc) 2.74 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const ava_1 = require("ava"); const prray_1 = require("../src/prray"); const test_utils_1 = require("./test-utils"); const func1 = (pre, c) => pre + c; const func2 = (pre, c) => { pre.push(c + 1); return pre; }; ava_1.default('prray reduce 1', (t) => __awaiter(this, void 0, void 0, function* () { const p = prray_1.prray([1, 2, 3]); // FIXME: 无法确定 reduce 的结果是不是数组,应该让 PrrayPromise 处理和兼容非数组的情况? // t.true(p.reduce(func1) instanceof PrrayPromise) // t.true(p.reduce(funcAsync1) instanceof PrrayPromise) t.deepEqual(p.reduce(func1), [1, 2, 3].reduce(func1)); t.deepEqual(p.reduce(func1, 10), [1, 2, 3].reduce(func1, 10)); })); ava_1.default('prray reduce 2', (t) => __awaiter(this, void 0, void 0, function* () { const p = prray_1.prray([1, 2, 3]); // t.true(p.reduce(func2, []) instanceof PrrayPromise) // t.true(p.reduce(funcAsync2, []) instanceof PrrayPromise) t.deepEqual(p.reduce(func2, []), [1, 2, 3].reduce(func2, [])); t.deepEqual(p.reduce(func2, []), [1, 2, 3].reduce(func2, [])); })); ava_1.default('prraypromise reduce 1', (t) => __awaiter(this, void 0, void 0, function* () { const pp = test_utils_1.toPrrayPromise([1, 2, 3]); // FIXME: 无法确定 reduce 的结果是不是数组,应该让 PrrayPromise 处理和兼容非数组的情况? // t.true(pp.reduce(func1) instanceof PrrayPromise) // t.true(pp.reduce(funcAsync1) instanceof PrrayPromise) t.deepEqual(yield pp.reduce(func1), [1, 2, 3].reduce(func1)); t.deepEqual(yield pp.reduce(func1, 10), [1, 2, 3].reduce(func1, 10)); })); ava_1.default('prraypromise reduce 2', (t) => __awaiter(this, void 0, void 0, function* () { const pp = test_utils_1.toPrrayPromise([1, 2, 3]); // t.true(pp.reduce(func2, []) instanceof PrrayPromise) // t.true(pp.reduce(funcAsync2, []) instanceof PrrayPromise) t.deepEqual(yield pp.reduce(func2, []), [1, 2, 3].reduce(func2, [])); t.deepEqual(yield pp.reduce(func2, []), [1, 2, 3].reduce(func2, [])); }));