@_rj_/array-extensions 中文文档教程
array-extensions
数组对象的一组扩展使处理它们变得更容易,既不是唯一的也不是新的,并且从其他语言、stackoverflow 和其他 github 项目中获得了很多灵感:)
包括 TypeScript 定义文件。
Usage:
(另请参阅更多使用模式的测试)
import "array-extensions";
// async/await
await [1,2,3].forEachAsync(async (item) => {
// do something await/async with {item}
})
// then/cath/finally
[4,5,6].forEachAsync(async (item) => {
// do something async with {item}
}).then(() => {
// execute something when done
})
Available functions
// proper sequential forEach on async functions
Array<T>.forEachAsync(async callback): Promise<void>
//Concurrent async forEach, with threadCount
Array<T>.forEachAsyncConcurrent(async callback: (item: T) => void, threadCount = 4, continueOnError = true): Promise<void>
// proper sequential map on async functions
Array<T>.mapAsync<TT>(async callback: (item: T) => TT): Promise<TT>
// Concurrent async map, with threadCount
Array<T>.mapAsyncConcurrent<TT>(async callback: (item: T) => TT, threadCount = 4, continueOnError = true): Promise<TT>
// simple reduce groupby,
Array<T>.groupBy(propName: string)
Array<T>.groupBy(callback: (item: T) => string)
// Following function should say it all, will add more over time (Only works on number arrays)
Array<T>.max(callback: (item: T): number): number
Array<T>.min(callback: (item: T): number): number
Array<T>.sum(callback: (item: T): number): number
array-extensions
A set of extensions to the array object to make dealing with them easier, neither unique or new, and with lots of inspiration from other languages, stackoverflow and other github projects :)
Includes TypeScript definition files.
Usage:
(Also see tests for more usage patterns)
import "array-extensions";
// async/await
await [1,2,3].forEachAsync(async (item) => {
// do something await/async with {item}
})
// then/cath/finally
[4,5,6].forEachAsync(async (item) => {
// do something async with {item}
}).then(() => {
// execute something when done
})
Available functions
// proper sequential forEach on async functions
Array<T>.forEachAsync(async callback): Promise<void>
//Concurrent async forEach, with threadCount
Array<T>.forEachAsyncConcurrent(async callback: (item: T) => void, threadCount = 4, continueOnError = true): Promise<void>
// proper sequential map on async functions
Array<T>.mapAsync<TT>(async callback: (item: T) => TT): Promise<TT>
// Concurrent async map, with threadCount
Array<T>.mapAsyncConcurrent<TT>(async callback: (item: T) => TT, threadCount = 4, continueOnError = true): Promise<TT>
// simple reduce groupby,
Array<T>.groupBy(propName: string)
Array<T>.groupBy(callback: (item: T) => string)
// Following function should say it all, will add more over time (Only works on number arrays)
Array<T>.max(callback: (item: T): number): number
Array<T>.min(callback: (item: T): number): number
Array<T>.sum(callback: (item: T): number): number