项目作者: Iplaylf2

项目描述 :
Like stream, but no stream.
高级语言: TypeScript
项目地址: git://github.com/Iplaylf2/no-stream.git
创建时间: 2021-03-01T09:20:44Z
项目社区:https://github.com/Iplaylf2/no-stream

开源协议:BSD 3-Clause "New" or "Revised" License

下载


no-stream

Like stream, but no stream.

English | 中文
-

feature

  • Similar to array, easy to use.
  • Support async.
  • Efficient.

install

  1. npm install no-stream

usage

  1. import { ns } from "no-stream";
  2. const s = ns(function* () {
  3. let x = 0;
  4. while (true) {
  5. yield x++;
  6. }
  7. }); // ns([0, 1, 2...])
  8. const result = s
  9. .map((x) => x * 2)
  10. .filter((x) => x % 4 === 0)
  11. .take(10)
  12. .reduce((r, x) => r + x, 0);
  13. console.log(result); // 180

benchmark

Benchmark which map n times and reduce once. from benchmark.ts

array

map times \ ops/sec \ array length 100 1000 10000 100000
2 1159961 23041 2462 184
3 184536 19075 1947 140
4 151335 13333 1561 114
5 127720 12334 1359 90.35

no-stream

map times \ ops/sec \ array length 100 1000 10000 100000
2 400500 45295 4820 481
3 276977 34394 3599 349
4 216729 26527 2751 265
5 180349 22585 2199 224

no-stream is more efficient!

document