Obliterator

2.0.5 · active · verified Sun Apr 19

Obliterator is a JavaScript/TypeScript library designed to provide higher-order functions for working with iterators and iterable-like values. It offers a suite of utilities for common iterable operations such as chaining multiple iterators, generating combinations and permutations, filtering, mapping, and consuming iterators. A key differentiator is its pragmatic approach to iterables, treating standard sequences like arrays and strings as valid inputs for convenience, even if they aren't strict ES6 iterables. The current stable version is 2.0.5, and it ships with full TypeScript declarations. The library is actively maintained, with the latest update noted in January 2025 on npm, focusing on utility functions for managing data streams and collections.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates creating an iterator, applying filter and map transformations, chaining with other iterables, and highlights a key `combinations` gotcha.

import { Iterator, filter, map, chain } from 'obliterator';

// Create an iterator from multiple values
const numbers = Iterator.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

// Filter for even numbers
const evenNumbers = filter(numbers, (n: number) => n % 2 === 0);

// Map to their squares
const squaredEvenNumbers = map(evenNumbers, (n: number) => n * n);

// Chain with another iterable (e.g., a simple array)
const combined = chain(squaredEvenNumbers, [121, 144, 169]);

console.log('Processed numbers:');
for (const value of combined) {
  console.log(value);
}

// Demonstrate combinations - careful with object mutation!
import { combinations } from 'obliterator';
const arr = ['A', 'B', 'C'];
const combos = combinations(arr, 2);

let firstCombo: string[] = [];
let secondCombo: string[] = [];

firstCombo = Array.from(combos.next().value);
secondCombo = Array.from(combos.next().value);

console.log('First combination:', firstCombo); // Should be ['A', 'B']
console.log('Second combination:', secondCombo); // Should be ['A', 'C']

view raw JSON →