Comparing version 1.1.0 to 1.1.1
@@ -114,2 +114,24 @@ /** | ||
const createTakeWhileIterable = (iterable, predicate) => new IterableCreatorIterable(function* take() { | ||
for (const item of iterable) { | ||
if (!predicate(item)) { | ||
break; | ||
} | ||
yield item; | ||
} | ||
}); | ||
const createSkipWhileIterable = (iterable, predicate) => new IterableCreatorIterable(function* skip() { | ||
let startTaking = false; | ||
for (const item of iterable) { | ||
if (startTaking) { | ||
yield item; | ||
} | ||
else if (!predicate(item)) { | ||
yield item; | ||
startTaking = true; | ||
} | ||
} | ||
}); | ||
const identityPredicateFn = (x) => x; | ||
@@ -336,2 +358,19 @@ const defaultComparer = (a, b) => { | ||
/** | ||
* Bypasses elements in a sequence as long as a specified condition is true | ||
* and then returns the remaining elements. | ||
* | ||
* @param predicate A function to test each element for a condition. | ||
* | ||
* @example | ||
* ```ts | ||
* // Returns [3, 4, 5] | ||
* from([1, 2, 3, 4, 5]) | ||
* .skipWhile(i => i < 3) | ||
* .toArray(); | ||
* ``` | ||
*/ | ||
skipWhile(predicate) { | ||
return new Sequence(createSkipWhileIterable(this._iterable, predicate)); | ||
} | ||
/** | ||
* Returns true if sequence contains an element for which the given | ||
@@ -376,2 +415,19 @@ * predicate returns a truthy value. | ||
/** | ||
* Returns elements from a sequence as long as a specified condition is true, | ||
* and then skips the remaining elements. | ||
* | ||
* @param predicate A function to test each element for a condition. | ||
* | ||
* @example | ||
* ```ts | ||
* // Returns [1, 2] | ||
* from([1, 2, 3, 4, 5]) | ||
* .takeWhile(i => i < 3) | ||
* .toArray(); | ||
* ``` | ||
*/ | ||
takeWhile(predicate) { | ||
return new Sequence(createTakeWhileIterable(this._iterable, predicate)); | ||
} | ||
/** | ||
* Converts the sequence to an array | ||
@@ -378,0 +434,0 @@ * |
@@ -120,2 +120,24 @@ (function (global, factory) { | ||
const createTakeWhileIterable = (iterable, predicate) => new IterableCreatorIterable(function* take() { | ||
for (const item of iterable) { | ||
if (!predicate(item)) { | ||
break; | ||
} | ||
yield item; | ||
} | ||
}); | ||
const createSkipWhileIterable = (iterable, predicate) => new IterableCreatorIterable(function* skip() { | ||
let startTaking = false; | ||
for (const item of iterable) { | ||
if (startTaking) { | ||
yield item; | ||
} | ||
else if (!predicate(item)) { | ||
yield item; | ||
startTaking = true; | ||
} | ||
} | ||
}); | ||
const identityPredicateFn = (x) => x; | ||
@@ -342,2 +364,19 @@ const defaultComparer = (a, b) => { | ||
/** | ||
* Bypasses elements in a sequence as long as a specified condition is true | ||
* and then returns the remaining elements. | ||
* | ||
* @param predicate A function to test each element for a condition. | ||
* | ||
* @example | ||
* ```ts | ||
* // Returns [3, 4, 5] | ||
* from([1, 2, 3, 4, 5]) | ||
* .skipWhile(i => i < 3) | ||
* .toArray(); | ||
* ``` | ||
*/ | ||
skipWhile(predicate) { | ||
return new Sequence(createSkipWhileIterable(this._iterable, predicate)); | ||
} | ||
/** | ||
* Returns true if sequence contains an element for which the given | ||
@@ -382,2 +421,19 @@ * predicate returns a truthy value. | ||
/** | ||
* Returns elements from a sequence as long as a specified condition is true, | ||
* and then skips the remaining elements. | ||
* | ||
* @param predicate A function to test each element for a condition. | ||
* | ||
* @example | ||
* ```ts | ||
* // Returns [1, 2] | ||
* from([1, 2, 3, 4, 5]) | ||
* .takeWhile(i => i < 3) | ||
* .toArray(); | ||
* ``` | ||
*/ | ||
takeWhile(predicate) { | ||
return new Sequence(createTakeWhileIterable(this._iterable, predicate)); | ||
} | ||
/** | ||
* Converts the sequence to an array | ||
@@ -384,0 +440,0 @@ * |
@@ -13,2 +13,4 @@ "use strict"; | ||
const sortBy_1 = require("./transforms/sortBy"); | ||
const takeWhile_1 = require("./transforms/takeWhile"); | ||
const skipWhile_1 = require("./transforms/skipWhile"); | ||
const identityPredicateFn = (x) => x; | ||
@@ -235,2 +237,19 @@ const defaultComparer = (a, b) => { | ||
/** | ||
* Bypasses elements in a sequence as long as a specified condition is true | ||
* and then returns the remaining elements. | ||
* | ||
* @param predicate A function to test each element for a condition. | ||
* | ||
* @example | ||
* ```ts | ||
* // Returns [3, 4, 5] | ||
* from([1, 2, 3, 4, 5]) | ||
* .skipWhile(i => i < 3) | ||
* .toArray(); | ||
* ``` | ||
*/ | ||
skipWhile(predicate) { | ||
return new Sequence(skipWhile_1.createSkipWhileIterable(this._iterable, predicate)); | ||
} | ||
/** | ||
* Returns true if sequence contains an element for which the given | ||
@@ -275,2 +294,19 @@ * predicate returns a truthy value. | ||
/** | ||
* Returns elements from a sequence as long as a specified condition is true, | ||
* and then skips the remaining elements. | ||
* | ||
* @param predicate A function to test each element for a condition. | ||
* | ||
* @example | ||
* ```ts | ||
* // Returns [1, 2] | ||
* from([1, 2, 3, 4, 5]) | ||
* .takeWhile(i => i < 3) | ||
* .toArray(); | ||
* ``` | ||
*/ | ||
takeWhile(predicate) { | ||
return new Sequence(takeWhile_1.createTakeWhileIterable(this._iterable, predicate)); | ||
} | ||
/** | ||
* Converts the sequence to an array | ||
@@ -277,0 +313,0 @@ * |
@@ -255,2 +255,17 @@ import { KeySelectorFn, ComparerFn, PredicateFn, MapFn, CallbackFn, Grouping, ReduceCallbackFn, NumberKeyedObject, StringKeyedObject } from "./types"; | ||
/** | ||
* Bypasses elements in a sequence as long as a specified condition is true | ||
* and then returns the remaining elements. | ||
* | ||
* @param predicate A function to test each element for a condition. | ||
* | ||
* @example | ||
* ```ts | ||
* // Returns [3, 4, 5] | ||
* from([1, 2, 3, 4, 5]) | ||
* .skipWhile(i => i < 3) | ||
* .toArray(); | ||
* ``` | ||
*/ | ||
skipWhile(predicate: PredicateFn<TItem>): Sequence<TItem>; | ||
/** | ||
* Returns true if sequence contains an element for which the given | ||
@@ -288,2 +303,17 @@ * predicate returns a truthy value. | ||
/** | ||
* Returns elements from a sequence as long as a specified condition is true, | ||
* and then skips the remaining elements. | ||
* | ||
* @param predicate A function to test each element for a condition. | ||
* | ||
* @example | ||
* ```ts | ||
* // Returns [1, 2] | ||
* from([1, 2, 3, 4, 5]) | ||
* .takeWhile(i => i < 3) | ||
* .toArray(); | ||
* ``` | ||
*/ | ||
takeWhile(predicate: PredicateFn<TItem>): Sequence<TItem>; | ||
/** | ||
* Converts the sequence to an array | ||
@@ -290,0 +320,0 @@ * |
{ | ||
"name": "fromfrom", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "LINQ inspired library to transform sequences of data", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
171941
58
2155