iterable-operator
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -87,1 +87,3 @@ export * from './is-iterable'; | ||
export * from './prefetch-async'; | ||
export * from './top'; | ||
export * from './top-async'; |
@@ -103,2 +103,4 @@ "use strict"; | ||
__exportStar(require("./prefetch-async"), exports); | ||
__exportStar(require("./top"), exports); | ||
__exportStar(require("./top-async"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -1,1 +0,2 @@ | ||
export declare function someAsync<T>(iterable: Iterable<T> | AsyncIterable<T>, predicate: (element: T, index: number) => Promise<unknown>): Promise<boolean>; | ||
import { Awaitable } from 'justypes'; | ||
export declare function someAsync<T>(iterable: Iterable<T> | AsyncIterable<T>, predicate: (element: T, index: number) => Awaitable<unknown>): Promise<boolean>; |
@@ -0,3 +1,5 @@ | ||
export declare type GetTypeOfIterable<T> = T extends Iterable<infer U> ? U : never; | ||
export declare function copyAsyncIterable<T>(iterable: AsyncIterable<T>): AsyncGenerator<Awaited<T>, void, unknown>; | ||
export declare function copyIterable<T>(iterable: Iterable<T>): Generator<T, void, unknown>; | ||
export declare type GetTypeOfIterable<T> = T extends Iterable<infer U> ? U : never; | ||
export declare function findInsertionIndex<T>(sortedArray: readonly T[], insertionElement: T, compare: (a: T, b: T) => number): number; | ||
export declare function getIntermediateIndex(startIndex: number, endIndex: number): number; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.copyIterable = exports.copyAsyncIterable = void 0; | ||
exports.getIntermediateIndex = exports.findInsertionIndex = exports.copyIterable = exports.copyAsyncIterable = void 0; | ||
async function* copyAsyncIterable(iterable) { | ||
@@ -16,2 +16,40 @@ for await (const element of iterable) { | ||
exports.copyIterable = copyIterable; | ||
function findInsertionIndex(sortedArray, insertionElement, compare) { | ||
if (sortedArray.length === 0) { | ||
return 0; | ||
} | ||
else { | ||
let startIndex = 0; | ||
let endIndex = sortedArray.length - 1; | ||
while (true) { | ||
const intermediateIndex = getIntermediateIndex(startIndex, endIndex); | ||
const result = compare(insertionElement, sortedArray[intermediateIndex]); | ||
if (result > 0) { | ||
startIndex = intermediateIndex + 1; | ||
if (startIndex > endIndex) { | ||
return startIndex; | ||
} | ||
} | ||
else if (result < 0) { | ||
endIndex = intermediateIndex; | ||
if (endIndex === startIndex) { | ||
return endIndex; | ||
} | ||
} | ||
else { | ||
for (let i = intermediateIndex; i < sortedArray.length; i++) { | ||
if (compare(insertionElement, sortedArray[intermediateIndex]) !== 0) { | ||
return i; | ||
} | ||
} | ||
return sortedArray.length; | ||
} | ||
} | ||
} | ||
} | ||
exports.findInsertionIndex = findInsertionIndex; | ||
function getIntermediateIndex(startIndex, endIndex) { | ||
return startIndex + Math.floor((endIndex - startIndex) / 2); | ||
} | ||
exports.getIntermediateIndex = getIntermediateIndex; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "iterable-operator", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Utilities for JavaScript Iterable and AsyncIterable", | ||
@@ -71,2 +71,3 @@ "keywords": [ | ||
"eslint": "^8.30.0", | ||
"extra-sort": "^0.1.1", | ||
"husky": "^4.3.8", | ||
@@ -73,0 +74,0 @@ "jest": "^29.3.1", |
@@ -680,3 +680,3 @@ # iterable-operator | ||
iterable: Iterable<T> | AsyncIterable<T> | ||
, predicate: (element: T, index: number) => Promise<unknown> | ||
, predicate: (element: T, index: number) => Awaitable<unknown> | ||
): Promise<boolean> | ||
@@ -739,3 +739,24 @@ ``` | ||
function prefetch<T>(iterable: Iterable<T>, size: number): AsyncIterableIterator<T> | ||
function prefetchAsync<T>(iterable: AsyncIterable<T>, size: number): AsyncIterableIterator<T> | ||
function prefetchAsync<T>( | ||
iterable: AsyncIterable<T> | ||
, size: number | ||
): AsyncIterableIterator<T> | ||
``` | ||
### top, topAsync | ||
```ts | ||
function top<T>( | ||
iterable: Iterable<T> | ||
, num: number | ||
, compare: (a: T, b: T) => number | ||
): T[] | ||
function topAsync<T>( | ||
iterable: AsyncIterable<T> | ||
, num: number | ||
, compare: (a: T, b: T) => number | ||
): Promise<T[]> | ||
``` | ||
```ts | ||
top([1, 2, 3], 2, (a, b) => b - a) // [3, 2] | ||
``` |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
166689
273
2303
761
0
18