LinqToTypeScript
LINQ to TypeScript
Install / Use
/learn @arogozine/LinqToTypeScriptREADME
LINQ To TypeScript
- Implementation of LINQ for TypeScript
- Targets TypeScript 5.6.X and ES 2022
await from([bing, google, quackQuackGo])
.asParallel()
.selectAsync(downloadHtml)
.select(getTitle)
.toArray()
Getting Started
npm i linq-to-typescript
tsconfig.json
"compilerOptions": {
"target": "es2022",
"lib": [
"es2022"
]
}
- The
strictTS option is recommended.
Using the Library
With Wrappers
// 0. Import Module
import { from } from "linq-to-typescript"
// To Use With Wrappers
const evenNumbers = from([1, 2, 3, 4, 5, 6, 7, 8, 9]).where((x) => x % 2 === 0).toArray()
Without Wrappers
// 0. Import Module
import { initializeLinq, IEnumerable } from "linq-to-typescript"
// 1. Declare that the JS types implement the IEnumerable interface
declare global {
interface Array<T> extends IEnumerable<T> { }
interface Uint8Array extends IEnumerable<number> { }
interface Uint8ClampedArray extends IEnumerable<number> { }
interface Uint16Array extends IEnumerable<number> { }
interface Uint32Array extends IEnumerable<number> { }
interface Int8Array extends IEnumerable<number> { }
interface Int16Array extends IEnumerable<number> { }
interface Int32Array extends IEnumerable<number> { }
interface Float32Array extends IEnumerable<number> { }
interface Float64Array extends IEnumerable<number> { }
interface Map<K, V> extends IEnumerable<[K, V]> { }
interface Set<T> extends IEnumerable<T> { }
interface String extends IEnumerable<string> { }
}
// 2. Bind Linq Functions to Array, Map, etc
initializeLinq()
// 3. Use without a wrapper type
const evenNumbers = [1, 2, 3, 4, 5, 6, 7, 8, 9].where((x) => x % 2 === 0).toArray()
Examples
Please refer to the examples folder
ES6 Modules (ESM)
To use library with ES6 modules make sure that you specify "type": "module" in package.json
API
TypeDoc API Surface Documentation
LinqToTypeScript implements the functionality of the IEnumerable interface
- IEnumerable, IAsyncEnumerable, and IParallelEnumerable interfaces are based on,
- IEnumerable<T> Interface
- Some changes made due to conflics with existing method names
- Some changes made due to limitations of JavaScript
IEnumerable
- Inspired by LINQ API Surface
- Has Async methods that return
PromiseorIAsyncEnumerable - Implements
Iterable<T> - Use
fromto wrap your arrays
IAsyncEnumerable
- Inspired by LINQ API Surface
- Has Async methods that return
PromiseorIAsyncEnumerable - For asynchronous iteration
- Implements
AsyncIterable<T>interface - Use
fromAsyncto wrap your AsyncIterable type
IParallelEnumerable
- Inspired by LINQ API Surface
- Has Async methods that return
PromiseorIParallelEnumerable - For asynchronous iteration in parallel (where possible)
- Implements
AsyncIterable<T>interface - Use
fromParallelto create a parallel enumeration
Shared Instance Methods
| Method | Async* | Tests Coverage | Notes |
|--------------------|---------|----------------|-------|
| aggregate | No | Sync
| all | Yes | Sync, Async
| any | Yes | Sync, Async
| append | No | Sync
| average | Yes | Sync, Async
| chunk | No | Sync
| concatenate | No | Sync | Equivalent to .Concat but renamed to avoid conflict with JS
| contains | Yes | Sync, Async
| count | Yes | Sync, Async
| defaultIfEmpty | No | Sync
| distinct | Yes | Sync, Async
| elementAt | No | Sync
| elementAtOrDefault | No | Sync
| except | Yes | Sync, Async
| first | Yes | Sync, Async
| firstOrDefault | Yes | Sync, Async
| each | Yes | Sync, Async | From List<T>.ForEach
| groupBy | Yes | Sync, Async
| groupByWithSel | No | Sync
| groupJoin | Yes | Sync, Async
| intersect | Yes | Sync, Async
| joinByKey | No | Sync
| last | Yes | Sync, Async
| lastOrDefault | Yes | Sync, Async
| max | Yes | Sync, Async
| min | Yes | Sync, Async
| ofType | No | Sync
| order | No | Sync
| orderBy | Yes | Sync, Async
| orderByDescending |
Related Skills
node-connect
341.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
Writing Hookify Rules
84.4kThis skill should be used when the user asks to "create a hookify rule", "write a hook rule", "configure hookify", "add a hookify rule", or needs guidance on hookify rule syntax and patterns.
review-duplication
99.5kUse this skill during code reviews to proactively investigate the codebase for duplicated functionality, reinvented wheels, or failure to reuse existing project best practices and shared utilities.
