npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rxjs-transducer

v1.1.1

Published

Transducer implementation leveraging RxJS operators to map, filter, reduce, take, skip on potentially infinite sequences

Downloads

169

Readme

rxjs-transducer

A transducer implementation using the excellent and well known operators from RxJS. The benefits are:

  • Performance: Doing a array.map().filter().reduce() causes the array to be iterated 3 times. Using rxjs-transducers, the array is only iterated once. Doing a filter().map().Math.max() on an array with 1,000,000 items is roughly three times as fast with the transducer as with normal array operations.
  • Ability to work with lazy and infinite collections (generators)
  • Access to a huge library of well tested operators from RxJS such as map, filter, reduce, skip, take, takeWhile, and many others
  • Full TypeScript support

Installation

npm install rxjs-transducer --save

Usage

TypeScript / ES6

import { transducer } from 'rxjs-transducer';
import { map, filter, reduce, skip, take } from 'rxjs/operators';
const source = ['a', 'ab', 'abc', 'abcd', 'abcde'];

// Works as standard array map and filter, but faster (only one iteration)
const result = transducer(source)(
  map(word => word.toUpperCase()),
  filter(word => word.length > 2)
);
// result -> ['ABC', 'ABCD', 'ABCDE']

// Note that results is always an array, even if the final operator
// only produces a single result
const result = transducer(source)(
  map(word => word.toUpperCase()),
  filter(word => word.length > 2),
  reduce((acc, s) => `${acc}-${s}`)
);
// result -> ['ABC-ABCD-ABCDE']

// Works with infinte sequences too
const result = transducer(integers())(
  map(i => i * 2),
  filter(i => i % 10 === 0),
  skip(10),
  take(5)
);
// result -> [100, 110, 120, 130, 140]

// Infinite sequence of integers from zero -> infinite
function* integers() {
  let i = 0;
  while (true) {
    yield i++;
  }
}

Javascript

const { map, filter, reduce, take, skip } = require('rxjs/operators');
const transducer = require('rxjs-transducer');
const source = ['a', 'ab', 'abc', 'abcd', 'abcde'];

const result = transducer(source)(
  map(word => word.toUpperCase()),
  filter(word => word.length > 2)
);
// result -> ['ABC', 'ABCD', 'ABCDE']

Test

npm run test