Linq
- A simple library that mimics the C# Linq Enumerable for Typescript.
There are two formats
- The fluent format
- 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}`);
}
}