Skip to content
Brad Sickles edited this page Nov 15, 2016 · 29 revisions

IEnumerable<T>

Provides an interface for enumerating data sets, transforming, and manipulating data.

Methods (* - deferred execution)

getEnumerator

getEnumerator(): IEnumerator<T>;

Creates an enumerator on this enumerable.

aggregate

aggregate<TAccumulate>(seed: TAccumulate, accumulator: (acc: TAccumulate, cur: T) => TAccumulate): TAccumulate;

Aggregates items beginning with a seed value and an accumulator function.

all

all(predicate?: (t: T, index?: number) => boolean): boolean;

Verifies that projections of all items using the predicate function evaluate to true.

any

any(predicate?: (t: T, index?: number) => boolean): boolean;

Verifies that a projection of any item using the predicate function evaluates to true.

append (v0.4.0)

append(...items: T[]): IEnumerable<T>;

Does not enumerate. Creates an IEnumerable by appending the input items. This allows individual items to be inserted at the end of the enumeration.

apply

apply<T>(action: (t: T, index?: number) => void): IEnumerable<T>;

Does not enumerate. Creates an IEnumerable that applies action function to all items.

at

at(index: number): T;

Retrieves the item at index.

average

average(selector?: (t: T) => number): number;

Aggregates all items by taking the average. The optional selector function can be used to project items to numbers.

concat

concat(second: IEnumerable<T>): IEnumerable<T>;
concat(second: T[]): IEnumerable<T>;

Does not enumerate. Creates a single IEnumerable with this items immediately preceding items from second.

count

count(predicate?: (t: T) => boolean): number;

Counts the number of items. The optional predicate function can be used to filter items.

distinct

distinct(comparer?: (f: T, s: T) => boolean): IEnumerable<T>;

Creates an IEnumerable with distinct items. If comparer is not specified, uses strict equality === to check for distinctness. Otherwise, comparer is used to verify whether f and s are the same.

except

except(second: IEnumerable<T>, comparer?: (f: T, s: T) => boolean): IEnumerable<T>;
except(second: T[], comparer?: (f: T, s: T) => boolean): IEnumerable<T>;

Creates an IEnumerable from the set complement (this \ second). If comparer is not specified, uses strict equality === to compare. Otherwise, comparer is used to verify whether f and s are the same.

first

first(match?: (t: T) => boolean): T;

Finds the first item that passes the match function. If no match function is specified, returns the first item. If this enumerable is empty, returns undefined.

firstIndex

firstIndex (match?: (t: T) => boolean): number;

Finds the first item that passes the match function. If there are no items, returns -1. If no match function is specified, this will return -1 with an empty enumerable or 0 with a non-empty enumerable.

groupBy

groupBy<TKey>(keySelector: (t: T) => TKey, comparer?: (k1: TKey, k2: TKey) => boolean): IEnumerable<IGrouping<TKey, T>>;

Groups items into IEnumerable<IGrouping<TKey, T>> using the keySelector function to project a key element. If comparer is not specified, uses strict equality === to compare the keys from keySelector function. Otherwise, comparer is used to verify k1 and k2 are the same. The first key seen in a group will be used as the key in the group. See IGrouping.

intersect

intersect(second: IEnumerable<T>, comparer?: (f: T, s: T) => boolean): IEnumerable<T>;
intersect(second: T[], comparer?: (f: T, s: T) => boolean): IEnumerable<T>;

Creates an IEnumerable from the set intersection (thissecond). If comparer is not specified, strict equality === is used to compare. Otherwise, comparer is used to verify whether f and s are the same.

join

join<TInner, TKey, TResult>(inner: IEnumerable<TInner>, outerKeySelector: (t: T) => TKey, innerKeySelector: (t: TInner) => TKey, resultSelector: (o: T, i: TInner) => TResult, comparer?: (k1: TKey, k2: TKey) => boolean): IEnumerable<TResult>;
join<TInner, TKey, TResult>(inner: TInner[], outerKeySelector: (t: T) => TKey, innerKeySelector: (t: TInner) => TKey, resultSelector: (o: T, i: TInner) => TResult, comparer?: (k1: TKey, k2: TKey) => boolean): IEnumerable<TResult>;

Creates an IEnumerable from the set cross product (this × inner). Items are included where resulting keys from outerKeySelector and innerKeySelector match. If comparer is not specified, strict equality === is used to compare. Otherwise, comparer is used to verify whether k1 and k2 are the same.

last

last(match?: (t: T) => boolean): T;

Finds the last item that matches match function. If no match function is specified, returns the last item. If this enumerable is empty, returns undefined.

lastIndex

lastIndex (match?: (t: T) => boolean): number;

Finds the last item that passes the match function. If there are no items, returns -1. If no match function is specified, this will return -1 with an empty enumerable or (n - 1) with a non-empty enumerable.

max

max(selector?: (t: T) => number): number;

Uses Math.max to determine the max of all items. The optional selector function can be used to project items to numbers.

min

min(selector?: (t: T) => number): number;

Uses Math.min to determine the min of all items. The optional selector function can be used to project items to numbers.

orderBy

orderBy<TKey>(keySelector: (t: T) => TKey, comparer?: (f: TKey, s: TKey) => number): IOrderedEnumerable<T>;

Does not enumerate. Creates an IOrderedEnumerable by ordering based on the key from the keySelector function. The optional comparer function can be used for custom comparison.

orderByDescending

orderByDescending<TKey>(keySelector: (t: T) => TKey, comparer?: (f: TKey, s: TKey) => number): IOrderedEnumerable<T>;

Does not enumerate. Creates an IOrderedEnumerable by ordering in descending order based on the key from the keySelector function. The optional comparer function can be used for custom comparison.

prepend (v0.4.0)

prepend(...items: T[]): IEnumerable<T>;

Does not enumerate. Creates an IEnumerable by prepending the input items. This allows individual items to be inserted at the beginning of the enumeration.

reverse

reverse(): IEnumerable<T>;

Creates an IEnumerable from the reverse order of items.

select

select<TResult>(selector: (t: T, index?: number) => TResult): IEnumerable<TResult>;

Does not enumerate. Projects items to new objec

selectMany

selectMany<TResult>(selector: (t: T) => IEnumerable<TResult>): IEnumerable<TResult>;
selectMany<TResult>(selector: (t: T) => TResult[]): IEnumerable<TResult>;

Does not enumerate. Creates an IEnumerable from a flattened projection of elements. The selector function should return an IEnumerable or Array that is used to concatenate to the resulting IEnumerable.

skip

skip(count: number): IEnumerable<T>;

Does not enumerate. Creates an IEnumerable that begins after count items.

skipWhile

skipWhile(predicate: (t: T, index?: number) => boolean): IEnumerable<T>;

Does not enumerate. Creates an IEnumerable skipping items while predicate function is satisfied.

sum

sum(selector?: (t: T) => number): number;

Adds all items. Can optionally project items to numbers using selector function.

take

take(count: number): IEnumerable<T>;

Does not enumerate. Creates an IEnumerable that only takes count items.

takeWhile

takeWhile(predicate: (t: T, index?: number) => boolean): IEnumerable<T>;

Does not enumerate. Creates an IEnumerable that takes items while predicate function is satisfied.

toArray

toArray(): T[];

Enumerates items and places into an array.

traverse

traverse(selector: (t: T) => T[]): IEnumerable<T>;
traverse(selector: (t: T) => IEnumerable<T>): IEnumerable<T>;

(v0.2.9) Does not enumerate. Creates an IEnumerable that traverses a hierarchical data structure. Resulting IEnumerable is a pre-order traversal of the tree using selector to walk children.

traverseUnique

traverseUnique(selector: (t: T) => T[], matcher?: (t1: T, t2: T) => boolean): IEnumerable<T>;
traverseUnique(selector: (t: T) => IEnumerable<T>, matcher?: (t1: T, t2: T) => boolean): IEnumerable<T>;

(v0.2.10) Does not enumerate. Traverses just like traverse with circular reference checking. Uses optional matcher to test equality. If matcher is not specified, uses === to test for equality.

union

union(second: IEnumerable<T>, comparer?: (f: T, s: T) => boolean): IEnumerable<T>;
union(second: T[], comparer?: (f: T, s: T) => boolean): IEnumerable<T>;

Creates an IEnumerable from the set union (thissecond). If comparer is not specified, uses strict equality === to compare. Otherwise, comparer is used to verify whether f and s are the same.

where

where(filter: (t: T) => boolean): IEnumerable<T>;

Does not enumerate. Creates an IEnumerable with items that satisfy filter function.

zip

zip<TSecond, TResult>(second: IEnumerable<TSecond>, resultSelector: (f: T, s: TSecond) => TResult): IEnumerable<TResult>;
zip<TSecond, TResult>(second: TSecond[], resultSelector: (f: T, s: TSecond) => TResult): IEnumerable<TResult>;

Creates an IEnumerable from a matching of elements from this and second. Items matching indices are passed through the resultSelector function to create a resulting object.