3.3.0 • Published 8 years ago

iter v3.3.0

Weekly downloads
13
License
MIT
Repository
github
Last release
8 years ago

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:

3.3.0

8 years ago

3.2.0

8 years ago

3.1.0

8 years ago

3.0.1

8 years ago

3.0.0

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.0.1-security

8 years ago

2.0.0

8 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

11 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago

0.0.0

11 years ago