@cological/linq

A Typescript implementation of the .Net Enumerable

Usage no npm install needed!

<script type="module">
  import cologicalLinq from 'https://cdn.skypack.dev/@cological/linq';
</script>

README

Linq

  • A simple library that mimics the C# Linq Enumerable for Typescript.

There are two formats

  1. The fluent format
  2. The piping format

Example using the fluent format:

import { enumerable } from '@cological/linq';

...

const groups =
    enumerable([1, 2, 3, 4])
        .orderByDescending(num => num)
        .groupBy(num => num % 2);

for (const group of groups) {
    console.log(group.key === 0 ? 'even' : 'odd');
    for (const num of group) {
        console.log(`    {num}`);
    }
}

Example using the piping format:

import { linq } from '@cological/linq';
import { groupBy, orderByDescending } from '@cological/linq/functions';

const groups = linq(
    [1, 2, 3, 4]
    orderByDescending(num => num),
    groupBy(num => num % 2)
);

for (const group of groups) {
    console.log(group.key === 0 ? 'even' : 'odd');
    for (const num of group) {
        console.log(`    {num}`);
    }
}