https://github.com/berhalak/fromit
Linq for js Iterables
https://github.com/berhalak/fromit
iterables linq
Last synced: 5 months ago
JSON representation
Linq for js Iterables
- Host: GitHub
- URL: https://github.com/berhalak/fromit
- Owner: berhalak
- License: mit
- Created: 2020-02-17T21:40:51.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-12T20:06:33.000Z (almost 3 years ago)
- Last Synced: 2025-03-06T06:51:24.675Z (10 months ago)
- Topics: iterables, linq
- Language: TypeScript
- Homepage:
- Size: 267 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://gitpod.io/#https://github.com/berhalak/linq)
# fromit
Linq style (like in c#) using generators
```sh
npm install fromit
```
Or use directly
```html
```
```ts
import { from } from "fromit";
const list = new Set([1, 2, 3]);
expect(
from(list)
.filter(x => x > 2)
.first()
).toBe(3);
const a = [1, 2, 3];
const b = [3, 4, 5];
let r = from(a).intersect(b);
expect(r.count()).toBe(1);
// speed up array functions
const slow = [...from(1000)].map(x=> x + 1).find(x=> x == 4);
const fast = from(1000).map(x=> x + 1).find(x => x == 4);
// used with async await
async function* generator() {
yield 1;
yield 2;
yield 3;
}
async function promise(): Promise {
return [1, 2, 3];
}
const result1 = from(generator());
const result2 = from(promise());
expect(await result1.toArray()).toStrictEqual(await result2.toArray());
```