0.0.6 • Published 3 years ago

each-once v0.0.6

Weekly downloads
236
License
BSD-3-Clause
Repository
github
Last release
3 years ago

each-once

For each item in collection once.

English | 中文

feature

  • Easy to use.
  • Data structure is basic.
  • Efficient.

install

npm install each-once

usage

import { combine, map, filter, take, reduce } from "each-once";

const tf = combine(
  map((x: number) => x * 2),
  filter((x: number) => x % 4 === 0),
  take<number>(10)
);

const transduce = reduce((r, x) => r + x, 0, tf);

const s = function* () {
  let x = 0;
  while (true) {
    yield x++;
  }
};

const result = transduce(s()); // transduce([0, 1, 2...])

console.log(result); // 180

benchmark

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

array

map times \ ops/sec \ array length100100010000100000
21193319287992688195
3199984222482166155
4167229173631685126
514409214313135696.84

each-once

map times \ ops/sec \ array length100100010000100000
2524905506615370562
3373222383854066397
4284126313293133315
5233850252142499242

each-once is more efficient!

document