Skip to main content

Iter Version Build Status

A bunch of utilities for working with iterables, many inspired by the native array methods.

Iterables are great for doing things you would normally do with arrays, lazily, meaning you only compute what you need. The aim of this module is to provide lazy iterable alternatives to javascript’s native array methods, as well as a few quality-of-life iterable utilities.

Usage

The module is currently hosted on deno.land/x/.

import * as iter from "https://deno.land/x/iter/mod.ts";
// or with a version
import * as iter from "https://deno.land/x/iter@v2.2.0/mod.ts";

const naturals = iter.create.increments(1);
const odds = iter.filter(naturals, (n) => n % 2 === 1);

for (const num of iter.take(odds, 5)) {
  console.log(num);
}

These curried methods are also available in the main mod.ts through iter.curried.

Functional programming

An alternative module is provided for functional programming styles, with a sensible level of currying.

import * as iter from "https://deno.land/x/iter/fp.ts";
// or with a version
import * as iter from "https://deno.land/x/iter@v2.2.0/fp.ts";

const naturals = iter.create.increments(1);
const filterOdds = iter.filter<number>((n) => n % 2 === 1);
const odds = filterOdds(naturals);

for (const num of iter.take(5)(odds)) {
  console.log(num);
}

API

Full API documentation can be found here

Array.prototype parity completeness

  • concat
  • entries (as indexedPairs)
  • every
  • filter
  • find
  • findIndex
  • includes
  • map
  • reduce
  • some

Currently not being considered

  • copyWithin
  • fill
  • flat
  • flatMap
  • forEach
  • indexOf
  • join
  • lastIndexOf
  • pop
  • push
  • reduceRight
  • reverse
  • shift
  • slice
  • sort
  • splice
  • toLocaleString
  • toString
  • unshift