array-linq
v1.0.6
Published
LINQ methods for TypeScript arrays
Downloads
53
Maintainers
Readme
array-linq
LINQ-like methods for TypeScript arrays
Test Coverage
| Statements | Branches | Functions | Lines | Build Status | | --------------------------------------------- | ----------------------------------------- | ------------------------------------------- | ----------------------------------- | ----------------------------------------------- | | | | | | |
Usage
Installation
npm install array-linq
Sample
import "array-linq"
array
.where(item => item.value < 10)
.selectMany(item => item.children, (i, c) => ({ item: i, child: c }))
.select(x => x.item.value * 10 + x.child.value)
.average();
Caveats
Keep in mind that this library modifies Array object prototype. If you use other libraries that affect the prototype, conflicts may occur resulting in unexpected behaviour.
Available methods
aggregate<TAccumulate, TResult>(
seed: TAccumulate,
func: (accumulator: TAccumulate, element: T) => TAccumulate,
resultSelector: (accumulator: TAccumulate) => TResult
): TResult;
all(predicate: (element: T) => boolean): boolean;
any(predicate: (element: T) => boolean): boolean;
append(element: T): T[];
average(): number;
average(selector: (element: T) => number): number;
contains(elment: T): boolean;
count(): number;
defultIfEmpty(defaultValue: T): T[];
distinct(): T[];
elementAt(index: number): T;
elementAtOrUndefined(index: number): T | undefined;
except(second: T[]): T[];
first(): T;
first(prdicate: (element: T) => boolean): T;
firstOrUndefined(): T | undefined;
firstOrUndefined(prdicate: (element: T) => boolean): T | undefined;
groupBy<TKey>(keySelector: (element: T) => TKey): Map<TKey, T[]>;
groupJoin<TInner, TKey, TResult>(
inner: TInner[],
outerKeySelector: (element: T) => TKey,
innerKeySelector: (innerElement: TInner) => TKey,
resultSelector: (element: T, innerElements: TInner[]) => TResult
): TResult[];
innerJoin<TInner, TKey, TResult>(
inner: TInner[],
outerKeySelector: (element: T) => TKey,
innerKeySelector: (innerElement: TInner) => TKey,
resultSelector: (element: T, innerElement: TInner) => TResult
): TResult[];
intersect(second: T[]): T[];
last(): T;
last(prdicate: (element: T) => boolean): T;
lastOrUndefined(): T | undefined;
lastOrUndefined(prdicate: (element: T) => boolean): T | undefined;
max(): number;
max(selector: (element: T) => number): number;
min(): number;
min(selector: (element: T) => number): number;
orderBy<TKey>(keySelector: (element: T) => TKey): T[];
orderByDescending<TKey>(keySelector: (element: T) => TKey): T[];
prepend(element: T): T[];
reverseImmutable(): T[];
select<TResult>(selector: (element: T, index: number) => TResult): TResult[];
selectMany<TCollection, TResult>(
collectionSelector: (element: T, index: number) => TCollection[],
resultSelector: (element: T, child: TCollection) => TResult
): TResult[];
sequenceEqual(second: T[]): boolean;
single(): T;
single(prdicate: (element: T) => boolean): T;
singleOrUndefined(): T | undefined;
singleOrUndefined(prdicate: (element: T) => boolean): T | undefined;
skip(count: number): T[];
skipLast(count: number): T[];
skipWhile(predicate: (element: T) => boolean): T[];
take(count: number): T[];
takeLast(count: number): T[];
takeWhile(predicate: (element: T) => boolean): T[];
sum(): number;
sum(selector: (element: T) => number): number;
toDictionary<TKey, TElement>(
keySelector: (element: T) => TKey,
elementSelector: (element: T) => TElement
): Map<TKey, TElement>;
toHashSet(): Set<T>;
union(second: T[]): T[];
where(predicate: (element: T) => boolean): T[];
zip<TSecond, TResult>(
second: TSecond[],
resultSelector: (firstElement: T, secondElement: TSecond) => TResult
): TResult[];