fromit
TypeScript icon, indicating that this package has built-in type declarations

2.2.11 • Public • Published

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());

Readme

Keywords

Package Sidebar

Install

npm i fromit

Weekly Downloads

3

Version

2.2.11

License

MIT

Unpacked Size

210 kB

Total Files

19

Last publish

Collaborators

  • berhalak