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

sequential-js

v0.0.3

Published

Array-like implementation in JavaScript that employs delayed execution techniques using generators.

Downloads

5

Readme

SequentialJS

A Sequence is like an Array but for a sequential list. A Sequence is an Iterator, yes, but it is more than that. It utilizes something called defferred execution. This is a technology that avoids expensive operations on a sequence until its items are evaluated.

Consider the following example.

const sequence = new Sequence(enormousList);
const mappedSequence = sequence.map(expensiveMapper);
const filteredSequence = sequence.filter(convolutedPredicate);

// At this point none of these callback are called.
const fifthItem = filteredSequence.at(4);

When fifthItem is retrieved, expensiveMapper and convolutedPredicate are each only called 5 times, the number of iterations until the sequence gets to the 5th element.

What is more, each step is invoked for each element in tern.

  • The 0th element is retrieved from the enormousList.
  • expensiveMapper is called on the 0th element.
  • convolutedPredicate is called on the 0th element.
  • The 1st element is retrieved from the enormousList.
  • expensiveMapper is called on the 0th element.
  • convolutedPredicate is called on the 0th element. ...
  • The 4th element is retrieved from the enormousList.
  • expesniveMapper is called on the 4th element.
  • convolutedPredicate is called on the 4th element.
  • The 4th element is returned.

Uses Most of the Array Interface

Sequence uses most of the same method of the Array type with the same signature.

The methods push and unshift are changed to do return the mutated sequence instead of mutating the sequece itself.

const newSequence = sequence.push(5);

The benefit of this is that the sequence does not need to be realized in order to push the value 5 onto the end of it.

The methods pop and shift are left out because they do not fit this pattern. The return an element and so cannot return a mutated sequence.

A workaround for this is as follows:

const poppedValue = sequence.toArray().pop();

Since the sequence is converted into an array it is completely sequenced into memory.

Other methods that mutate the state of the array are left out as well. These are reverse, sort, and splice. You can use the methods toReversed, toSorted, and toSpliced instead as they fit the returned mutation pattern.

The reversed methods findLast, findLastIndex, and lastIndexOf must iterate the sequence from beginning to end and hang on to the last matching element. Because of this, it is probably faster to convert the sequence to an array and call these methods on that.