New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

iterable-fns

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

iterable-fns

Functions for working with built-in iterable types

  • 1.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

Iterable Functions

npm version GitHub issues TypeDoc docs Travis Coveralls Dev Dependencies styled with prettier

Really simple functions for working with iterable types, inspired by F#'s seq module design.

Features

  • Full type-safety with TypeScript
  • Zero dependency
  • Pure functions

Installation

Add package using NPM or yarn

npm i --save iterable-fns
yarn add iterable-fns

You can import the top level modules directly:

import { groupBy } from 'iterable-fns'

Examples

Calculating primes lazily with iterators can either be done by calling each of the basic functions:

import { count, initRaw, map, filter } from '../src/iterable-fns'

const range = initRaw({ from: 1, to: 100 })
const mapped = map(range, (x) => ({
  x,
  factors: filter(initRaw({ from: 1, to: x }), (y) => x % y === 0),
}))
const filtered = filter(mapped, (num) => count(num.factors) === 2)
const primes = map(filtered, (num) => num.x)

or can utilise the chain methods:

import { init } from 'iterable-fns'

const primes = init({ from: 1, to: 100 })
  .map((x) => ({
    x,
    factors: init({ from: 1, to: x }).filter((y) => x % y === 0),
  }))
  .filter((num) => num.factors.count() === 2)
  .map((num) => num.x)

for (const prime of primes) {
  console.log(prime)
}

Grouping numbers into odd and even buckets

import { init, toArray } from 'iterable-fns'

const oddAndEven = init({ from: 1, to: 25 })
  .groupBy((i) => (i % 2 === 0 ? 'even' : 'odd'))
  .map(([key, values]) => [key, toArray(values)])

NPM scripts

  • yarn test: Run test suite
  • yarn start: Run yarn build in watch mode
  • yarn test:watch: Run test suite in interactive watch mode
  • yarn test:prod: Run linting and generate coverage
  • yarn build: Generate bundles and typings, create docs
  • yarn lint: Lints code
  • yarn commit: Commit using conventional commit style (husky will tell you to use it if you haven't :wink:)

Keywords

FAQs

Package last updated on 23 May 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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc