Socket
Socket
Sign inDemoInstall

augmentative-iterable

Package Overview
Dependencies
0
Maintainers
8
Versions
38
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    augmentative-iterable

This project is just a template for creation of new projects


Version published
Weekly downloads
455
decreased by-1.52%
Maintainers
8
Install size
35.7 kB
Created
Weekly downloads
 

Changelog

Source

1.5.11

  • c34530a fix: improving sync iteration performance
  • 7ab8740 1.5.10
  • 4dfb1ce fix: speeding up foreach async operation

Readme

Source

Actions Status Actions Status Test Coverage Maintainability Packages npm version

This library offers some operations over iterables with the intention of a better performance overall.

How this works?

To explain this, I'll give a quick explanation about iterables because the functionality of this library is indeed very technical. When you create an iterable in js like that:

function* myGenerator() {
  yield 1;
  yield 2;
  yield 3;
}

And, then, create another iterable, like this:

function myGenerator2() {
  for (const item of myGenerator()) {
    yield item * 2;
  }
}

And use it like this:

Array.from(myGenerator2());

What node is doing behind the scenes?

  • By Array.from operation, it starts the iterator of myGenerator2;
  • It starts the iterator of myGenerator;
  • It iterates over myGenerator iterator;
  • It iterates over myGenerator2 iterator;
  • It generate a new value from the multiplication yielded by the myGenerator2 iterator;
  • It pushes it into a new array, returned, after the iteration is over, by the Array.from function;

What is wrong with that? It works as expected, and in many scenarios is the best option after all. But, it creates an overload in the core of the language to make it all operational. It's in that point this library try to offer another option.

How the library would work, then? Let's take the first iterable and reuse it, but applying transformations of this library:

const myGenerator2 = mapIterable(myGenerator(), (x) => x * 2);

This operation, internally, returns a new iterable with a reference to the first iterable, and a list of operations that will be applied over it. This list, as you may guess, will have the provided multiplication. At this point, nothing more efficient will happen if you run Array.from, but let's say you do a little more:

const myGenerator3 = mapIterable(myGenerator2(), (x) => x + 2);
const myGenerator4 = filterIterable(myGenerator3(), (x) => x % 2 === 0);
const myGenerator5 = takeWhileIterable(myGenerator4(), (x) => x > 10);

Now, you have 5 transformations, and how the resulting iterable will look like?

  • It, still have a reference for the first iterable, but no reference to any other;
  • The list of operations I talked about above will have all the chained operations provided;

So, when you run Array.from over myGenerator5, it will use this data to process the iterable, and nothing else. The steps of such process can be described like this:

  • By Array.from operation, it starts the iterator of myGenerator5;
  • It starts the iterator of myGenerator;
  • It iterates over the array of operations applying each one;
  • It pushes it into a new array, returned, after the iteration is over, by the Array.from function;

This process requires less overload and is more scalable than the first one and still have the same result. By our tests, we have saved over 80% of processing time in some cases. Even though the setup of the iterable using this approach shows to be heavier, the process that really matter is the iteration, which surpasses any milliseconds you had lost preparing it. Another thing we tried to do here is to avoid the use of async operation everytime possible, as it's also another source of overload.

And how all those helper methods works?

This library actually have been made to have the base functionalities of @codibre/fluent-iterable, so, at this first version, it's not really simple to use as for some methods you have to rely on bind or call uses for some functions, but checkout our index file where we described each exported function if you want to try it!

License

Licensed under MIT.

FAQs

Last updated on 22 Jun 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc