iterable-transformers
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -5,3 +5,3 @@ { | ||
"typings": "./target/src/index.d.ts", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"scripts": { | ||
@@ -8,0 +8,0 @@ "lint": "tslint --project tsconfig.json --type-check", |
@@ -25,3 +25,3 @@ # iterable-transformers | ||
|`take`|TODO|TODO| | ||
|`takeWhile`|TODO|TODO| | ||
|`takeWhile`|✅|✅| | ||
|`takeUntil`|TODO|TODO| | ||
@@ -28,0 +28,0 @@ |`drop`|TODO|TODO| |
import './AsyncIteratorSymbolPolyfill'; | ||
export declare const map: <TSource, TResult>(fn: (value: TSource) => TResult) => (source: AsyncIterable<TSource>) => AsyncIterableIterator<TResult>; | ||
export declare const flatten: <TSource>(source: AsyncIterable<AsyncIterable<TSource>>) => AsyncIterableIterator<TSource>; | ||
export declare const map: <TSource, TResult>(fn: (value: TSource) => TResult) => (source: AsyncIterable<TSource>) => AsyncIterable<TResult>; | ||
export declare const flatten: <TSource>(source: AsyncIterable<AsyncIterable<TSource>>) => AsyncIterable<TSource>; | ||
export declare const reduce: <Acc, TSource>(reducer: (acc: Acc, t: TSource) => Acc) => (initialValue: Acc) => (source: AsyncIterable<TSource>) => Promise<Acc>; | ||
export declare const toArray: <TSource>(source: AsyncIterable<TSource>) => Promise<TSource[]>; | ||
export declare const takeWhile: <TSource>(predicate: (t: TSource) => boolean) => (source: AsyncIterable<TSource>) => AsyncIterable<TSource>; |
@@ -71,28 +71,45 @@ "use strict"; | ||
}; | ||
exports.reduce = (reducer) => (initialValue) => function (source) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const iterator = source[Symbol.asyncIterator](); | ||
const recurse = (iterator, acc) => __awaiter(this, void 0, void 0, function* () { | ||
const iteratorResult = yield iterator.next(); | ||
if (iteratorResult.done) { | ||
return acc; | ||
exports.reduce = (reducer) => (initialValue) => (source) => __awaiter(this, void 0, void 0, function* () { | ||
const iterator = source[Symbol.asyncIterator](); | ||
const recurse = (iterator, acc) => __awaiter(this, void 0, void 0, function* () { | ||
const iteratorResult = yield iterator.next(); | ||
if (iteratorResult.done) { | ||
return acc; | ||
} | ||
else { | ||
const { value } = iteratorResult; | ||
const nextAcc = reducer(acc, value); | ||
return recurse(iterator, nextAcc); | ||
} | ||
}); | ||
return recurse(iterator, initialValue); | ||
}); | ||
exports.toArray = (source) => __awaiter(this, void 0, void 0, function* () { | ||
const reducer = (acc, t) => { | ||
acc.push(t); | ||
return acc; | ||
}; | ||
return exports.reduce(reducer)([])(source); | ||
}); | ||
exports.takeWhile = (predicate) => function (source) { | ||
return __asyncGenerator(this, arguments, function* () { | ||
try { | ||
for (var source_3 = __asyncValues(source), source_3_1 = yield ["await", source_3.next()]; !source_3_1.done; source_3_1 = yield ["await", source_3.next()]) { | ||
const value = source_3_1.value; | ||
if (!predicate(value)) { | ||
break; | ||
} | ||
yield ["yield", value]; | ||
} | ||
else { | ||
const { value } = iteratorResult; | ||
const nextAcc = reducer(acc, value); | ||
return recurse(iterator, nextAcc); | ||
} | ||
catch (e_3_1) { e_3 = { error: e_3_1 }; } | ||
finally { | ||
try { | ||
if (source_3_1 && !source_3_1.done && (_a = source_3.return)) yield ["await", _a.call(source_3)]; | ||
} | ||
}); | ||
return recurse(iterator, initialValue); | ||
finally { if (e_3) throw e_3.error; } | ||
} | ||
var e_3, _a; | ||
}); | ||
}; | ||
exports.toArray = function (source) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const reducer = (acc, t) => { | ||
acc.push(t); | ||
return acc; | ||
}; | ||
return exports.reduce(reducer)([])(source); | ||
}); | ||
}; | ||
//# sourceMappingURL=AsyncIterable.js.map |
@@ -1,4 +0,5 @@ | ||
export declare const map: <TSource, TResult>(fn: (value: TSource) => TResult) => (source: Iterable<TSource>) => IterableIterator<TResult>; | ||
export declare const flatten: <TSource>(source: Iterable<Iterable<TSource>>) => IterableIterator<TSource>; | ||
export declare const map: <TSource, TResult>(fn: (value: TSource) => TResult) => (source: Iterable<TSource>) => Iterable<TResult>; | ||
export declare const flatten: <TSource>(source: Iterable<Iterable<TSource>>) => Iterable<TSource>; | ||
export declare const reduce: <Acc, TSource>(reducer: (acc: Acc, t: TSource) => Acc) => (initialValue: Acc) => (source: Iterable<TSource>) => Acc; | ||
export declare const toArray: <TSource>(source: Iterable<TSource>) => TSource[]; | ||
export declare const toArray: <TSource>(source: Iterable<TSource>) => Iterable<TSource>; | ||
export declare const takeWhile: <TSource>(predicate: (t: TSource) => boolean) => (source: Iterable<TSource>) => Iterable<TSource>; |
@@ -13,3 +13,3 @@ "use strict"; | ||
}; | ||
exports.reduce = (reducer) => (initialValue) => function (source) { | ||
exports.reduce = (reducer) => (initialValue) => (source) => { | ||
const iterator = source[Symbol.iterator](); | ||
@@ -30,3 +30,3 @@ const recurse = (iterator, acc) => { | ||
// TODO: Delegate to Array.from instead? | ||
exports.toArray = function (source) { | ||
exports.toArray = (source) => { | ||
const reducer = (acc, t) => { | ||
@@ -38,2 +38,10 @@ acc.push(t); | ||
}; | ||
exports.takeWhile = (predicate) => function* (source) { | ||
for (const value of source) { | ||
if (!predicate(value)) { | ||
break; | ||
} | ||
yield value; | ||
} | ||
}; | ||
//# sourceMappingURL=Iterable.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
13858
188