TypeScript code example
import LinqArray from "../src/LinqArray";
let jsItems = [2, 4, 6, 8, 1, 3, 5, 7]; // Standard JS array of numbers
let items1 = new LinqArray<number>(jsItems); // items1 is of type LinqArray<number>, constructed from the standard JS array of numbers
let items2 = new LinqArray(jsItems); // Simplified constructor where generic type (number) is inferred from the source array
let firstOver4Times10 = items2
.where((i) => i > 4) // items > 4
.select((i) => i * 10) // multiply by 10
.orderBy((i) => i) // order ascending
.first(); // first item
let expected = 50;
expect(firstOver4Times10).toEqual(expected);LinqArray includes equivalents of these common .NET LINQ, Generic and Array methods:
- aggregate
- all
- any
- append
- average
- chunk
- concat
- contains
- count
- defaultIfEmpty
- distinct
- distinctBy
- elementAt
- elementAtOrDefault
- empty
- except
- exceptBy
- first
- firstOrDefault
- groupBy
- groupJoin
- indexOf2 (new)
- intersect
- intersectBy
- join (implemented as join2)
- last
- lastOrDefault
- max
- maxBy
- min
- minBy
- order
- orderBy
- orderByDescending
- orderDescending
- prepend
- range
- repeat
- reverse (implemented as reverse2)
- select
- selectMany
- sequenceEqual
- setValue
- single
- singleOrDefault
- skip
- skipLast
- skipWhile
- sum
- take
- takeLast
- takeWhile
- thenBy (to be implemented as part of Enumerable.ts)
- thenByDescending (to be implemented as part of Enumerable.ts)
- toArray (to be implemented as part of Enumerable.ts)
- toDictionary
- union
- where
- zip