[go: up one dir, main page]

Skip to content

berhalak/fromit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gitpod Ready-to-Code

fromit

Linq style (like in c#) using generators

npm install fromit

Or use directly

<script src="https://unpkg.com/fromit/dist/fromit.min.js"></script>
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<number[]> {
  return [1, 2, 3];
}

const result1 = from(generator());
const result2 = from(promise());

expect(await result1.toArray()).toStrictEqual(await result2.toArray());

About

Linq for js Iterables

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published