@_rj_/array-extensions 中文文档教程

发布于 3年前 浏览 20 项目主页 更新于 3年前

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
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文