Iter8or

new Iter8or(iterable, optionsopt)

Creates an instance of Iter8or.
Parameters:
NameTypeAttributesDefaultDescription
iterableIterable | AsyncIterable | number | ObjectThe iterable object to use as the source data set.
optionsObject<optional>
{}An object with additional options.
Properties
NameTypeAttributesDefaultDescription
digitsboolean<optional>
falseIf true, an iterator is created over the digits of a number.
asyncboolean<optional>
falseIf true, an asynchronous iterator is created.
Throws:
If `iterable` is null, undefined, boolean, or function.
Type
TypeError

Methods

avg(fnopt) → {number}

Calculates the average of the elements in the iterable.
Parameters:
NameTypeAttributesDescription
fnfunction<optional>
Optional mapping function to apply before averaging.
Returns:
The average value.
Type: 
number
Example
const iter = new Iter8or([1, 2, 3]);
const average = iter.avg();
console.log(average); // 2

concat(…iterators) → {Iter8or}

Concatenates the current iterable with other Iter8or instances.
Parameters:
NameTypeAttributesDescription
iteratorsIter8or<repeatable>
The iterators to concatenate.
Throws:
Throws if any of the provided iterators are not instances of Iter8or.
Type
Error
Returns:
A new instance with the concatenated iterable.
Type: 
Iter8or
Example
const iter1 = new Iter8or([1, 2]);
const iter2 = new Iter8or([3, 4]);
const concatenated = iter1.concat(iter2);
console.log([...concatenated]); // [1, 2, 3, 4]

drop(n) → {Iter8or}

Drops the first `n` elements from the iterable.
Parameters:
NameTypeDescription
nnumberThe number of elements to drop.
Returns:
A new instance with the dropped iterable.
Type: 
Iter8or
Example
const iter = new Iter8or([1, 2, 3, 4]);
const dropped = iter.drop(2);
console.log([...dropped]); // [3, 4]

filter(predicate) → {Iter8or}

Filters the iterable using the provided predicate function.
Parameters:
NameTypeDescription
predicatefunctionThe filtering function.
Returns:
A new instance with the filtered iterable.
Type: 
Iter8or
Example
const iter = new Iter8or([1, 2, 3, 4]);
const filtered = iter.filter(x => x % 2 === 0);
console.log([...filtered]); // [2, 4]

flat(depth) → {Iter8or}

Flattens the iterable up to the specified depth.
Parameters:
NameTypeDescription
depthnumberThe depth to flatten the iterable.
Returns:
A new instance with the flattened iterable.
Type: 
Iter8or
Example
const iter = new Iter8or([1, [2, [3, 4]]]);
const flattened = iter.flat(2);
console.log([...flattened]); // [1, 2, 3, 4]

flatMap(fn) → {Iter8or}

Maps and flattens the iterable using the provided function.
Parameters:
NameTypeDescription
fnfunctionThe function to map and flatten the iterable.
Returns:
A new instance with the flattened iterable.
Type: 
Iter8or
Example
const iter = new Iter8or([1, 2, 3]);
const flatMapped = iter.flatMap(x => [x, x * 2]);
console.log([...flatMapped]); // [1, 2, 2, 4, 3, 6]

map(fn) → {Iter8or}

Applies a function to all elements of the iterator and returns a new Iter8or instance.
Parameters:
NameTypeDescription
fnfunctionThe function to apply to each element of the iterator.
Returns:
A new Iter8or instance with the mapped values.
Type: 
Iter8or
Example
const iter = new Iter8or([1, 2, 3]);
const mapped = iter.map(x => x * 2);
console.log([...mapped]); // [2, 4, 6]

max(fnopt) → {number}

Finds the maximum value in the iterable.
Parameters:
NameTypeAttributesDescription
fnfunction<optional>
Optional mapping function to apply before finding the maximum.
Returns:
The maximum value.
Type: 
number
Example
const iter = new Iter8or([1, 2, 3]);
const maximum = iter.max();
console.log(maximum); // 3

min(fnopt) → {number}

Finds the minimum value in the iterable.
Parameters:
NameTypeAttributesDescription
fnfunction<optional>
Optional mapping function to apply before finding the minimum.
Returns:
The minimum value.
Type: 
number
Example
const iter = new Iter8or([1, 2, 3]);
const minimum = iter.min();
console.log(minimum); // 1

partition(predicate) → {Array}

Partitions the elements of the iterator into two groups based on the predicate function.
Parameters:
NameTypeDescription
predicatefunctionThe function that returns true or false for each element.
Returns:
An array of two arrays: [array of elements for which the predicate returned true, array of elements for which the predicate returned false].
Type: 
Array
Example
const iter = new Iter8or([1, 2, 3, 4, 5]);
const [evens, odds] = iter.partition(x => x % 2 === 0);
console.log(evens); // [2, 4]
console.log(odds);  // [1, 3, 5]

reduce(reducer, initialValueopt) → {*}

Reduces the iterable using the provided reducer function.
Parameters:
NameTypeAttributesDescription
reducerfunctionThe reducer function.
initialValue*<optional>
The initial value for the reduction.
Returns:
The reduced value.
Type: 
*
Example
const iter = new Iter8or([1, 2, 3]);
const sum = iter.reduce((acc, x) => acc + x, 0);
console.log(sum); // 6

reverse() → {Iter8or}

Reverses the order of the elements in the iterable.
Returns:
A new instance with the reversed iterable.
Type: 
Iter8or
Example
const iter = new Iter8or([1, 2, 3]);
const reversed = iter.reverse();
console.log([...reversed]); // [3, 2, 1]

sum(fnopt) → {number}

Sums the elements in the iterable.
Parameters:
NameTypeAttributesDescription
fnfunction<optional>
Optional mapping function to apply before summing.
Returns:
The sum of the elements.
Type: 
number
Example
const iter = new Iter8or([1, 2, 3]);
const totalSum = iter.sum();
console.log(totalSum); // 6

take(n) → {Iter8or}

Takes the first `n` elements from the iterable.
Parameters:
NameTypeDescription
nnumberThe number of elements to take.
Returns:
A new instance with the taken iterable.
Type: 
Iter8or
Example
const iter = new Iter8or([1, 2, 3, 4]);
const taken = iter.take(2);
console.log([...taken]); // [1, 2]

toArray() → {Array}

Collects the elements of the iterator into an array.
Returns:
An array containing all the elements of the iterator.
Type: 
Array
Example
const iter = new Iter8or(new Set([1, 2, 3]));
const array = iter.toArray();
console.log(array); // [1, 2, 3]

toMap() → {Map}

Collects the elements of the iterator into a Map. The elements must be pairs [key, value].
Returns:
A Map containing all the key-value pairs from the iterator.
Type: 
Map
Example
const iter = new Iter8or([['a', 1], ['b', 2], ['c', 3]]);
const map = iter.toMap();
console.log(map); // Map { 'a' => 1, 'b' => 2, 'c' => 3 }

toObject() → {Object}

Collects the elements of the iterator into an object. The elements must be pairs [key, value].
Returns:
An object containing all the key-value pairs from the iterator.
Type: 
Object
Example
const iter = new Iter8or([['a', 1], ['b', 2], ['c', 3]]);
const obj = iter.toObject();
console.log(obj); // { a: 1, b: 2, c: 3 }

toSet() → {Set}

Collects the elements of the iterator into a Set.
Returns:
A Set containing all unique elements of the iterator.
Type: 
Set
Example
const iter = new Iter8or([1, 2, 2, 3, 4]);
const set = iter.toSet();
console.log(set); // Set { 1, 2, 3, 4 }

toString() → {string}

Concatenates the elements of the iterator into a string.
Returns:
A string containing all the elements of the iterator concatenated together.
Type: 
string
Example
const iter = new Iter8or(['H', 'e', 'l', 'l', 'o']);
const str = iter.toString();
console.log(str); // 'Hello'

(static) next() → {IteratorResult}

Returns the next value in the iteration.
Returns:
The next value of the iterator.
Type: 
IteratorResult
Example
const iter = new Iter8or([1, 2, 3]);
console.log(iter.next().value); // Output: 1