iter
iter given function asynchronously
Last updated 13 years ago by npm .
BSD · Repository · Original npm · Tarball · package.json
$ cnpm install iter 
SYNC missed versions from official npm registry.

iter Build Status

Utility library for functional programming based on ES2015 generators that ensures lazy evaluation of possibly infinite ranges.

Examples

Fizzbuzz generator

import { compose, map, range, take } from 'iter';

const fizzBuzz = compose(
  map(n => n % 3 === 0 ? 'fizz' : n),
  map(n => n % 5 === 0 ? 'buzz' : n),
  map(n => n % 5 === 0 && n % 3 === 0 ? 'fizzbuzz' : n),
  range(1, Infinity)
);

[...take(15, fizzBuzz)]
  // => [1, 2, 'fizz', 4, 'buzz', 'fizz', 7, 8 , 'fizz', 'buzz', 11, 'fizz', 13, 14, 'fizzbuzz']

Fibonacci sequence up to the nth number

import { zipWith, tail, take } from 'iter';

const fibonacci = function * () {
  yield 0;
  yield 1;
  yield * zipWith((x, y) => x + y, fibonacci(), tail(fibonacci()));
};

[...take(8, fibonacci())]
  // => [0, 1, 1, 2, 3, 5, 8, 13]

Methods

  • assertIterable(iterable)
  • compact(iterable)
  • compose(...iterables)
  • filter(filterFn, iterable)
  • isIterable(iterable)
  • map(mapFn, iterable)
  • pluck(iterable)
  • slice(fromIdx, len, iterable)
  • tail(iterable)
  • take(num, iterable)
  • unqiue(iterable)
  • zipWith(zipFn, ...iterables)

Inspiration & further reading:

Current Tags

  • 3.3.0                                ...           latest (10 years ago)

22 Versions

  • 3.3.0                                ...           10 years ago
  • 3.2.0                                ...           10 years ago
  • 3.1.0                                ...           10 years ago
  • 3.0.1                                ...           10 years ago
  • 3.0.0                                ...           10 years ago
  • 1.1.2                                ...           10 years ago
  • 1.1.1                                ...           10 years ago
  • 1.1.0                                ...           10 years ago
  • 1.0.1                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
  • 0.0.1-security                                ...           10 years ago
  • 2.0.0                                ...           10 years ago
  • 0.0.9                                ...           12 years ago
  • 0.0.8                                ...           12 years ago
  • 0.0.7                                ...           12 years ago
  • 0.0.6                                ...           12 years ago
  • 0.0.5                                ...           12 years ago
  • 0.0.4                                ...           12 years ago
  • 0.0.3                                ...           12 years ago
  • 0.0.2                                ...           12 years ago
  • 0.0.1                                ...           12 years ago
  • 0.0.0                                ...           13 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 18
Last Day 0
Last Week 18
Last Month 1
Dependencies (0)
None
Dev Dependencies (1)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |