@bodar/totallylazy
Advanced tools
Comparing version 0.173.23 to 0.175.25
@@ -31,2 +31,4 @@ import {Predicate} from "./predicates"; | ||
reject(predicate: Predicate<A>): Contract<A>; | ||
find(predicate: Predicate<A>): Contract<A>; | ||
@@ -58,2 +60,4 @@ | ||
reject(predicate: Predicate<A>): Collection<A>; | ||
find(predicate: Predicate<A>): Collection<A>; | ||
@@ -85,2 +89,4 @@ | ||
reject(predicate: Predicate<A>): AsyncCollection<A>; | ||
find(predicate: Predicate<A>): AsyncCollection<A>; | ||
@@ -87,0 +93,0 @@ |
{ | ||
"name": "@bodar/totallylazy", | ||
"version": "0.173.23", | ||
"version": "0.175.25", | ||
"description": "Totallylazy", | ||
@@ -5,0 +5,0 @@ "repository": "git@github.com:bodar/totallylazy.js.git", |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function not(predicate) { | ||
return function (a) { return !predicate(a); }; | ||
} | ||
exports.not = not; | ||
function where(mapper, predicate) { | ||
@@ -4,0 +8,0 @@ return Object.assign(function (a) { return predicate(mapper(a)); }, { |
@@ -5,2 +5,6 @@ import {Mapper} from "./collections"; | ||
export function not<A>(predicate: Predicate<A>): Predicate<A> { | ||
return (a: A) => !predicate(a); | ||
} | ||
export interface Where<A, B> extends Predicate<A> { | ||
@@ -7,0 +11,0 @@ mapper: Mapper<A,B>, |
@@ -96,2 +96,5 @@ "use strict"; | ||
}; | ||
Sequence.prototype.reject = function (predicate) { | ||
return this.create(this.transducer.reject(predicate)); | ||
}; | ||
Sequence.prototype.find = function (predicate) { | ||
@@ -106,2 +109,8 @@ return Option.of(this.iterable, this.transducer.find(predicate)); | ||
}; | ||
Sequence.prototype.drop = function (count) { | ||
return this.create(this.transducer.drop(count)); | ||
}; | ||
Sequence.prototype.dropWhile = function (predicate) { | ||
return this.create(this.transducer.dropWhile(predicate)); | ||
}; | ||
Sequence.prototype.take = function (count) { | ||
@@ -161,2 +170,5 @@ return this.create(this.transducer.take(count)); | ||
}; | ||
AsyncSequence.prototype.reject = function (predicate) { | ||
return this.create(this.transducer.reject(predicate)); | ||
}; | ||
AsyncSequence.prototype.find = function (predicate) { | ||
@@ -171,2 +183,8 @@ return this.create(this.transducer.find(predicate)); | ||
}; | ||
AsyncSequence.prototype.drop = function (count) { | ||
return this.create(this.transducer.drop(count)); | ||
}; | ||
AsyncSequence.prototype.dropWhile = function (predicate) { | ||
return this.create(this.transducer.dropWhile(predicate)); | ||
}; | ||
AsyncSequence.prototype.take = function (count) { | ||
@@ -302,2 +320,5 @@ return this.create(this.transducer.take(count)); | ||
}; | ||
Single.prototype.reject = function (predicate) { | ||
return this.create(this.transducer.filter(predicate)); | ||
}; | ||
Single.prototype.find = function (predicate) { | ||
@@ -367,2 +388,5 @@ return this.create(this.transducer.find(predicate)); | ||
}; | ||
Option.prototype.reject = function (predicate) { | ||
return this.create(this.transducer.reject(predicate)); | ||
}; | ||
Option.prototype.find = function (predicate) { | ||
@@ -369,0 +393,0 @@ return this.create(this.transducer.find(predicate)); |
@@ -76,2 +76,6 @@ import { | ||
reject(predicate: Predicate<A>): Sequence<A> { | ||
return this.create(this.transducer.reject(predicate)); | ||
} | ||
find(predicate: Predicate<A>): Option<A> { | ||
@@ -89,2 +93,10 @@ return Option.of(this.iterable, this.transducer.find(predicate)); | ||
drop(count: number): Sequence<A> { | ||
return this.create(this.transducer.drop(count)); | ||
} | ||
dropWhile(predicate: Predicate<A>): Sequence<A> { | ||
return this.create(this.transducer.dropWhile(predicate)); | ||
} | ||
take(count: number): Sequence<A> { | ||
@@ -118,3 +130,3 @@ return this.create(this.transducer.take(count)); | ||
size(): number{ | ||
size(): number { | ||
return this.toArray().length; | ||
@@ -156,2 +168,6 @@ } | ||
reject(predicate: Predicate<A>): AsyncSequence<A> { | ||
return this.create(this.transducer.reject(predicate)); | ||
} | ||
find(predicate: Predicate<A>): AsyncSequence<A> { | ||
@@ -169,2 +185,10 @@ return this.create(this.transducer.find(predicate)); | ||
drop(count: number): AsyncSequence<A> { | ||
return this.create(this.transducer.drop(count)); | ||
} | ||
dropWhile(predicate: Predicate<A>): AsyncSequence<A> { | ||
return this.create(this.transducer.dropWhile(predicate)); | ||
} | ||
take(count: number): AsyncSequence<A> { | ||
@@ -201,3 +225,2 @@ return this.create(this.transducer.take(count)); | ||
} | ||
} | ||
@@ -274,2 +297,6 @@ | ||
reject(predicate: Predicate<A>): Single<A> { | ||
return this.create(this.transducer.filter(predicate)); | ||
} | ||
find(predicate: Predicate<A>): Single<A> { | ||
@@ -350,2 +377,6 @@ return this.create(this.transducer.find(predicate)); | ||
reject(predicate: Predicate<A>): Option<A> { | ||
return this.create(this.transducer.reject(predicate)); | ||
} | ||
find(predicate: Predicate<A>): Option<A> { | ||
@@ -352,0 +383,0 @@ return this.create(this.transducer.find(predicate)); |
@@ -5,2 +5,3 @@ "use strict"; | ||
var collections_1 = require("./collections"); | ||
var predicates_1 = require("./predicates"); | ||
var Transducer = /** @class */ (function () { | ||
@@ -30,2 +31,5 @@ function Transducer() { | ||
}; | ||
Transducer.prototype.reject = function (predicate) { | ||
return filter(predicates_1.not(predicate), this); | ||
}; | ||
Transducer.prototype.find = function (predicate) { | ||
@@ -40,2 +44,8 @@ return find(predicate, this); | ||
}; | ||
Transducer.prototype.drop = function (size) { | ||
return drop(size, this); | ||
}; | ||
Transducer.prototype.dropWhile = function (predicate) { | ||
return dropWhile(predicate, this); | ||
}; | ||
Transducer.prototype.take = function (count) { | ||
@@ -80,2 +90,5 @@ return take(count, this); | ||
}; | ||
Transducable.prototype.reject = function (predicate) { | ||
return this.create(this.transducer.reject(predicate)); | ||
}; | ||
Transducable.prototype.find = function (predicate) { | ||
@@ -896,2 +909,192 @@ return this.create(this.transducer.find(predicate)); | ||
exports.take = take; | ||
var DropTransducer = /** @class */ (function (_super) { | ||
tslib_1.__extends(DropTransducer, _super); | ||
function DropTransducer(count) { | ||
var _this = _super.call(this) || this; | ||
_this.count = count; | ||
return _this; | ||
} | ||
DropTransducer.prototype.async_ = function (iterable) { | ||
return tslib_1.__asyncGenerator(this, arguments, function async_9() { | ||
var e_15, _a, iterable_15, iterable_15_1, a, e_15_1; | ||
return tslib_1.__generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
_b.trys.push([0, 7, 8, 13]); | ||
iterable_15 = tslib_1.__asyncValues(iterable); | ||
_b.label = 1; | ||
case 1: return [4 /*yield*/, tslib_1.__await(iterable_15.next())]; | ||
case 2: | ||
if (!(iterable_15_1 = _b.sent(), !iterable_15_1.done)) return [3 /*break*/, 6]; | ||
a = iterable_15_1.value; | ||
if (!(--this.count < 0)) return [3 /*break*/, 5]; | ||
return [4 /*yield*/, tslib_1.__await(a)]; | ||
case 3: return [4 /*yield*/, _b.sent()]; | ||
case 4: | ||
_b.sent(); | ||
_b.label = 5; | ||
case 5: return [3 /*break*/, 1]; | ||
case 6: return [3 /*break*/, 13]; | ||
case 7: | ||
e_15_1 = _b.sent(); | ||
e_15 = { error: e_15_1 }; | ||
return [3 /*break*/, 13]; | ||
case 8: | ||
_b.trys.push([8, , 11, 12]); | ||
if (!(iterable_15_1 && !iterable_15_1.done && (_a = iterable_15.return))) return [3 /*break*/, 10]; | ||
return [4 /*yield*/, tslib_1.__await(_a.call(iterable_15))]; | ||
case 9: | ||
_b.sent(); | ||
_b.label = 10; | ||
case 10: return [3 /*break*/, 12]; | ||
case 11: | ||
if (e_15) throw e_15.error; | ||
return [7 /*endfinally*/]; | ||
case 12: return [7 /*endfinally*/]; | ||
case 13: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
DropTransducer.prototype.sync = function (iterable) { | ||
var e_16, _a, iterable_16, iterable_16_1, a, e_16_1; | ||
return tslib_1.__generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
_b.trys.push([0, 5, 6, 7]); | ||
iterable_16 = tslib_1.__values(iterable), iterable_16_1 = iterable_16.next(); | ||
_b.label = 1; | ||
case 1: | ||
if (!!iterable_16_1.done) return [3 /*break*/, 4]; | ||
a = iterable_16_1.value; | ||
if (!(--this.count < 0)) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, a]; | ||
case 2: | ||
_b.sent(); | ||
_b.label = 3; | ||
case 3: | ||
iterable_16_1 = iterable_16.next(); | ||
return [3 /*break*/, 1]; | ||
case 4: return [3 /*break*/, 7]; | ||
case 5: | ||
e_16_1 = _b.sent(); | ||
e_16 = { error: e_16_1 }; | ||
return [3 /*break*/, 7]; | ||
case 6: | ||
try { | ||
if (iterable_16_1 && !iterable_16_1.done && (_a = iterable_16.return)) _a.call(iterable_16); | ||
} | ||
finally { if (e_16) throw e_16.error; } | ||
return [7 /*endfinally*/]; | ||
case 7: return [2 /*return*/]; | ||
} | ||
}); | ||
}; | ||
return DropTransducer; | ||
}(Transducer)); | ||
exports.DropTransducer = DropTransducer; | ||
function drop(count, transducer) { | ||
return compose(new DropTransducer(count), transducer); | ||
} | ||
exports.drop = drop; | ||
var DropWhileTransducer = /** @class */ (function (_super) { | ||
tslib_1.__extends(DropWhileTransducer, _super); | ||
function DropWhileTransducer(predicate) { | ||
var _this = _super.call(this) || this; | ||
_this.predicate = predicate; | ||
return _this; | ||
} | ||
DropWhileTransducer.prototype.async_ = function (iterable) { | ||
return tslib_1.__asyncGenerator(this, arguments, function async_10() { | ||
var e_17, _a, shouldDrop, iterable_17, iterable_17_1, a, e_17_1; | ||
return tslib_1.__generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
shouldDrop = true; | ||
_b.label = 1; | ||
case 1: | ||
_b.trys.push([1, 8, 9, 14]); | ||
iterable_17 = tslib_1.__asyncValues(iterable); | ||
_b.label = 2; | ||
case 2: return [4 /*yield*/, tslib_1.__await(iterable_17.next())]; | ||
case 3: | ||
if (!(iterable_17_1 = _b.sent(), !iterable_17_1.done)) return [3 /*break*/, 7]; | ||
a = iterable_17_1.value; | ||
if (shouldDrop) | ||
shouldDrop = this.predicate(a); | ||
if (!!shouldDrop) return [3 /*break*/, 6]; | ||
return [4 /*yield*/, tslib_1.__await(a)]; | ||
case 4: return [4 /*yield*/, _b.sent()]; | ||
case 5: | ||
_b.sent(); | ||
_b.label = 6; | ||
case 6: return [3 /*break*/, 2]; | ||
case 7: return [3 /*break*/, 14]; | ||
case 8: | ||
e_17_1 = _b.sent(); | ||
e_17 = { error: e_17_1 }; | ||
return [3 /*break*/, 14]; | ||
case 9: | ||
_b.trys.push([9, , 12, 13]); | ||
if (!(iterable_17_1 && !iterable_17_1.done && (_a = iterable_17.return))) return [3 /*break*/, 11]; | ||
return [4 /*yield*/, tslib_1.__await(_a.call(iterable_17))]; | ||
case 10: | ||
_b.sent(); | ||
_b.label = 11; | ||
case 11: return [3 /*break*/, 13]; | ||
case 12: | ||
if (e_17) throw e_17.error; | ||
return [7 /*endfinally*/]; | ||
case 13: return [7 /*endfinally*/]; | ||
case 14: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
DropWhileTransducer.prototype.sync = function (iterable) { | ||
var e_18, _a, shouldDrop, iterable_18, iterable_18_1, a, e_18_1; | ||
return tslib_1.__generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
shouldDrop = true; | ||
_b.label = 1; | ||
case 1: | ||
_b.trys.push([1, 6, 7, 8]); | ||
iterable_18 = tslib_1.__values(iterable), iterable_18_1 = iterable_18.next(); | ||
_b.label = 2; | ||
case 2: | ||
if (!!iterable_18_1.done) return [3 /*break*/, 5]; | ||
a = iterable_18_1.value; | ||
if (shouldDrop) | ||
shouldDrop = this.predicate(a); | ||
if (!!shouldDrop) return [3 /*break*/, 4]; | ||
return [4 /*yield*/, a]; | ||
case 3: | ||
_b.sent(); | ||
_b.label = 4; | ||
case 4: | ||
iterable_18_1 = iterable_18.next(); | ||
return [3 /*break*/, 2]; | ||
case 5: return [3 /*break*/, 8]; | ||
case 6: | ||
e_18_1 = _b.sent(); | ||
e_18 = { error: e_18_1 }; | ||
return [3 /*break*/, 8]; | ||
case 7: | ||
try { | ||
if (iterable_18_1 && !iterable_18_1.done && (_a = iterable_18.return)) _a.call(iterable_18); | ||
} | ||
finally { if (e_18) throw e_18.error; } | ||
return [7 /*endfinally*/]; | ||
case 8: return [2 /*return*/]; | ||
} | ||
}); | ||
}; | ||
return DropWhileTransducer; | ||
}(Transducer)); | ||
exports.DropWhileTransducer = DropWhileTransducer; | ||
function dropWhile(predicate, transducer) { | ||
return compose(new DropWhileTransducer(predicate), transducer); | ||
} | ||
exports.dropWhile = dropWhile; | ||
var TakeWhileTransducer = /** @class */ (function (_super) { | ||
@@ -905,4 +1108,4 @@ tslib_1.__extends(TakeWhileTransducer, _super); | ||
TakeWhileTransducer.prototype.async_ = function (iterable) { | ||
return tslib_1.__asyncGenerator(this, arguments, function async_9() { | ||
var e_15, _a, iterable_15, iterable_15_1, a, e_15_1; | ||
return tslib_1.__asyncGenerator(this, arguments, function async_11() { | ||
var e_19, _a, iterable_19, iterable_19_1, a, e_19_1; | ||
return tslib_1.__generator(this, function (_b) { | ||
@@ -912,8 +1115,8 @@ switch (_b.label) { | ||
_b.trys.push([0, 9, 10, 15]); | ||
iterable_15 = tslib_1.__asyncValues(iterable); | ||
iterable_19 = tslib_1.__asyncValues(iterable); | ||
_b.label = 1; | ||
case 1: return [4 /*yield*/, tslib_1.__await(iterable_15.next())]; | ||
case 1: return [4 /*yield*/, tslib_1.__await(iterable_19.next())]; | ||
case 2: | ||
if (!(iterable_15_1 = _b.sent(), !iterable_15_1.done)) return [3 /*break*/, 8]; | ||
a = iterable_15_1.value; | ||
if (!(iterable_19_1 = _b.sent(), !iterable_19_1.done)) return [3 /*break*/, 8]; | ||
a = iterable_19_1.value; | ||
if (!this.predicate(a)) return [3 /*break*/, 5]; | ||
@@ -930,9 +1133,9 @@ return [4 /*yield*/, tslib_1.__await(a)]; | ||
case 9: | ||
e_15_1 = _b.sent(); | ||
e_15 = { error: e_15_1 }; | ||
e_19_1 = _b.sent(); | ||
e_19 = { error: e_19_1 }; | ||
return [3 /*break*/, 15]; | ||
case 10: | ||
_b.trys.push([10, , 13, 14]); | ||
if (!(iterable_15_1 && !iterable_15_1.done && (_a = iterable_15.return))) return [3 /*break*/, 12]; | ||
return [4 /*yield*/, tslib_1.__await(_a.call(iterable_15))]; | ||
if (!(iterable_19_1 && !iterable_19_1.done && (_a = iterable_19.return))) return [3 /*break*/, 12]; | ||
return [4 /*yield*/, tslib_1.__await(_a.call(iterable_19))]; | ||
case 11: | ||
@@ -943,3 +1146,3 @@ _b.sent(); | ||
case 13: | ||
if (e_15) throw e_15.error; | ||
if (e_19) throw e_19.error; | ||
return [7 /*endfinally*/]; | ||
@@ -953,3 +1156,3 @@ case 14: return [7 /*endfinally*/]; | ||
TakeWhileTransducer.prototype.sync = function (iterable) { | ||
var e_16, _a, iterable_16, iterable_16_1, a, e_16_1; | ||
var e_20, _a, iterable_20, iterable_20_1, a, e_20_1; | ||
return tslib_1.__generator(this, function (_b) { | ||
@@ -959,7 +1162,7 @@ switch (_b.label) { | ||
_b.trys.push([0, 6, 7, 8]); | ||
iterable_16 = tslib_1.__values(iterable), iterable_16_1 = iterable_16.next(); | ||
iterable_20 = tslib_1.__values(iterable), iterable_20_1 = iterable_20.next(); | ||
_b.label = 1; | ||
case 1: | ||
if (!!iterable_16_1.done) return [3 /*break*/, 5]; | ||
a = iterable_16_1.value; | ||
if (!!iterable_20_1.done) return [3 /*break*/, 5]; | ||
a = iterable_20_1.value; | ||
if (!this.predicate(a)) return [3 /*break*/, 3]; | ||
@@ -972,14 +1175,14 @@ return [4 /*yield*/, a]; | ||
case 4: | ||
iterable_16_1 = iterable_16.next(); | ||
iterable_20_1 = iterable_20.next(); | ||
return [3 /*break*/, 1]; | ||
case 5: return [3 /*break*/, 8]; | ||
case 6: | ||
e_16_1 = _b.sent(); | ||
e_16 = { error: e_16_1 }; | ||
e_20_1 = _b.sent(); | ||
e_20 = { error: e_20_1 }; | ||
return [3 /*break*/, 8]; | ||
case 7: | ||
try { | ||
if (iterable_16_1 && !iterable_16_1.done && (_a = iterable_16.return)) _a.call(iterable_16); | ||
if (iterable_20_1 && !iterable_20_1.done && (_a = iterable_20.return)) _a.call(iterable_20); | ||
} | ||
finally { if (e_16) throw e_16.error; } | ||
finally { if (e_20) throw e_20.error; } | ||
return [7 /*endfinally*/]; | ||
@@ -1005,3 +1208,3 @@ case 8: return [2 /*return*/]; | ||
SortTransducer.prototype.async_ = function (iterable) { | ||
return tslib_1.__asyncGenerator(this, arguments, function async_10() { | ||
return tslib_1.__asyncGenerator(this, arguments, function async_12() { | ||
var result; | ||
@@ -1008,0 +1211,0 @@ return tslib_1.__generator(this, function (_a) { |
@@ -1,8 +0,3 @@ | ||
import { | ||
array, | ||
ascending, | ||
Comparator, Contract, isAsyncIterable, isIterable, Mapper, | ||
Reducer | ||
} from "./collections"; | ||
import {Predicate} from "./predicates"; | ||
import {array, ascending, Comparator, Contract, isAsyncIterable, isIterable, Mapper, Reducer} from "./collections"; | ||
import {not, Predicate} from "./predicates"; | ||
@@ -41,2 +36,6 @@ export abstract class Transducer<A, B> implements Contract<B> { | ||
reject(predicate: Predicate<B>): Transducer<A, B> { | ||
return filter(not(predicate), this); | ||
} | ||
find(predicate: Predicate<B>): Transducer<A, B> { | ||
@@ -54,2 +53,10 @@ return find(predicate, this); | ||
drop(size: number): Transducer<A, B> { | ||
return drop(size, this); | ||
} | ||
dropWhile(predicate: Predicate<B>): Transducer<A, B> { | ||
return dropWhile(predicate, this); | ||
} | ||
take(count: number): Transducer<A, B> { | ||
@@ -102,2 +109,6 @@ return take(count, this); | ||
reject(predicate: Predicate<A>): Transducable<A> { | ||
return this.create(this.transducer.reject(predicate)); | ||
} | ||
find(predicate: Predicate<A>): Transducable<A> { | ||
@@ -396,3 +407,51 @@ return this.create(this.transducer.find(predicate)); | ||
export class DropTransducer<A> extends Transducer<A, A> { | ||
constructor(public count: number) { | ||
super(); | ||
} | ||
async* async_(iterable: AsyncIterable<A>): AsyncIterable<A> { | ||
for await (const a of iterable) { | ||
if (--this.count < 0) yield a; | ||
} | ||
} | ||
* sync(iterable: Iterable<A>): Iterable<A> { | ||
for (const a of iterable) { | ||
if (--this.count < 0) yield a; | ||
} | ||
} | ||
} | ||
export function drop<A, B>(count: number, transducer: Transducer<A, B>): Transducer<A, B> { | ||
return compose(new DropTransducer(count), transducer); | ||
} | ||
export class DropWhileTransducer<A> extends Transducer<A, A> { | ||
constructor(public predicate: Predicate<A>) { | ||
super(); | ||
} | ||
async* async_(iterable: AsyncIterable<A>): AsyncIterable<A> { | ||
let shouldDrop = true; | ||
for await (const a of iterable) { | ||
if (shouldDrop) shouldDrop = this.predicate(a); | ||
if (!shouldDrop) yield a; | ||
} | ||
} | ||
* sync(iterable: Iterable<A>): Iterable<A> { | ||
let shouldDrop = true; | ||
for (const a of iterable) { | ||
if (shouldDrop) shouldDrop = this.predicate(a); | ||
if (!shouldDrop) yield a; | ||
} | ||
} | ||
} | ||
export function dropWhile<A, B>(predicate: Predicate<B>, transducer: Transducer<A, B>): Transducer<A, B> { | ||
return compose(new DropWhileTransducer(predicate), transducer); | ||
} | ||
export class TakeWhileTransducer<A> extends Transducer<A, A> { | ||
@@ -399,0 +458,0 @@ constructor(public predicate: Predicate<A>) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
243453
4468