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

functor-iterable

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

functor-iterable

Iterable that implements optimized map method

latest
Source
npmnpm
Version
0.1.3
Version published
Maintainers
1
Created
Source

functor-iterable

travis ci npm version Coverage Status Dependency Status

functor-iterable exports a class that builds iterables that provide map method.

Install

$ npm install functor-iterable --save

Usage

const FunctorIterable = require('functor-iterable')

const iterable = new FunctorIterable([4, 2, 7, 8]) // (4 2 7 8)
    .map(e => 3 * e) // (12 6 21 24)
    .map(e => e / 2) // (6 3 10.5 12)



// converting to array:
[...iterable] // [6, 3, 10.5, 12]

// traversing values:
for (const val of iterable) {
    // ...
}

// creating an iterator that traverses the values
let iterator = iterable[Symbol.iterator]()
iterator.next() // {value: 6, done: false}
iterator.next() // {value: 3, done: false}
iterator.next() // {value: 10.5, done: false}
iterator.next() // {value: 12, done: false}
iterator.next() // {value: undefined, done: true}

// Infinite iterable
const naturals = {
    [Symbol.iterator]: function* () {
        let i = 1
        while(true) { yield i++ }
    }
} // (1 2 3 4...)

const collatzTransform = e => e % 2 === 1 ? 3 * e + 1 : e / 2

new FunctorIterable(naturals) // (1  2  3  4  5...)
    .map(collatzTransform) // (4  1 10  2 16...)
    .map(collatzTransform) // (2  4  5  1  8...)
    .map(collatzTransform) // (1  2 16  4  4...)
    .map(collatzTransform) // (4  1  8  2  2...)
    .map(collatzTransform) // (2  4  4  1  1...)

Support

  • Node.js >=6
  • ES2015 transpilers

License

MIT

Keywords

functor

FAQs

Package last updated on 20 May 2018

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