New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

yastream

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yastream

Yet another stream library

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

yastream

Yet another stream library

GitHub package.json version

Motivation

The use of streams is growing in so many languages, but JavaScript is still lacking this functionality natively.

You might say: "But javascript already has .map, .filter and many other functionalities over arrays." Don't get me wrong, it is enough for several use cases, but consider the following example:

[1, 2, 3, 4]
  .map(value => value * 2)
  .find(element => element > 2)
// expected output: 4

In this case, even though the result comes from the second position of the array, the map iterated all entries before trying to find the right element.

I believe that out there already exists many libraries that do this, but I decided to do my own version in order to learn more about JavaScript.

Installation

This module is distributed via npm:

npm install yastream

Stream operations

Everything begins when you create a stream: stream(array).

There are several operation you can perform over a stream, but some can be stacked and others are terminal. In order to solve the stream it is mandatory to perform a terminal operation

Stackable

  • map(map_function)
  • filter(condition)

Terminal

  • do()
  • count()
  • reduce(reducer_function, acc_start_value)
  • findFirst(condition)

Examples

For quick examples you can check bellow, but for complete functionality coverage you can look into the test files.

Map and filter array

const { stream } = require("yastream")

const result =
    stream([1, 2, 3])
        .map(value => value * 2)
        .filter(value => value > 3)
        .do();
// expected result = [4, 6]

Map, filter and find in array

const { stream } = require("yastream")

const result =
    stream([1, 2, 3])
        .map(value => value * 2)
        .filter(value => value > 3)
        .findFirst(value => value == 4);
// expected result = '4'
// it only iterates the first two element of the array

Keywords

npm

FAQs

Package last updated on 22 Feb 2020

Did you know?

Socket

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