Creates a new instance.
There is usually no need to create an instance directly. Prefer shortcut function iter
to wrap an Array
or other object supporting the iterable contract.
Functions that returns an Array
or other ES 2015 iterable.
The function is called lazily on each demand to start the iteration.
Iterator wrapped into this instance. Allows enumeration by using the for-of
syntax.
Similar to Array.concat
.
Concatenates another iterable after this one and returns a new IterableWrapper<T>
that
goes through both collections.
Another iterable such as this object or a plain Array.
A new iterable containing elements from both collections.
Checks whether an item is present in the collection.
Item to be found. Equality operator === is applied to compare with content of this collection.
true
if found. Otherwise false
.
Creates antoher iterable with distinct elements contained in the wrapped collection (removes duplicates).
A function that produces key used to distinguish among elements. Elements with duplicate keys are considered as duplicates. If not specified, the function uses comparison by equality operator ===.
Another iterable based on this one without duplicate elements.
Similar to Array.every
.
Evaluates whether all elements meet a condition.
Predicate that has to return true
when passed element meets the condition.
true
if all elements are accepted or the sequence is empty.
false
if one or more elements do not pass the given predicate.
Subtracts another collection from this one (performs set minus operation).
Creates new IterableWrapper<T>
which contains all source elements except elements in another collection.
Another IterableWrapper<T>
or Array<T>
.
Function that compares two elements. If ommitted, comparison will use equality operator ===.
Copy of this iterable sequence wihout elements found in another collection.
Similar to Array.filter
.
Creates a new IterableWrapper<T>
on top of this one that filters elements using a predicate.
Predicate that says whether to accept or reject an element.
Predicate is supposed to return true
to accept and false
to reject it.
New IterableWrapper<T>
with filtered content.
Similar to Array.find
.
Finds the first element that matches provided predicate.
Predicate that has to return true
when passed element is the desired one.
The found element or undefined
if none is found.
Similar to Array.findIndex
.
Finds the first element that matches provided predicate and returns its index. Returns -1 if not found.
Predicate that has to return true when passed element is the desired one.
Zero-based index of the found element or -1 if it's not found.
Accesses nested collections as a single iterable. Provide a mapper
function that is supposed
to return the nested Array
contained within the element.
This function makes a new IterableWrapper<TChildItem>
over all nested elements.
Returns nested collection for each element.
Iterable<TChildItem>
over all items in nested collections.
Flattens a tree-like structure.
Creates an IterableWrapper<T>
that recursivelly walks through all elements.
Function that is supposed to return nested collection. Each element in the nested collection
may contain another nested collection which will be processed in the same way.
If the function returns undefined
, it means that the gived element has no nested items
or you want to skip them.
IterableWrapper<T>
over the full tree-like structure.
Flattens a tree-like structure and creates new elements based on the source.
Creates an IterableWrapper<T>
that recursivelly walks through all elements.
Additionally maps each element passing it to a mapper function.
Function that is supposed to return nested collection. Each element in the nested collection
may contain another nested collection which will be processed in the same way.
If the function returns undefined
, it means that the gived element has no nested items
or you want to skip them.
Function that converts each item. Called lazily on demand.
IterableWrapper<T>
over the full tree-like structure.
Similar to Array.forEach
.
Executes a function on each element in the iterable sequence.
Function executed on each element.
Retrieves an element at given index.
0-based index
Element at the index. Throws an error if the index is out of range.
Groups content of the collection into another IterableWrapper
.
Each item is a group object with key
and items
.
key
is the value generated by given keyMapper
functions. Equality === is used to determine what keys are the same.
items
is array of elements belonging to the group distinguished by key
.
Makes a key for each element in the collection.
Collection of groups with key and items associated with the key.
Returns the first element in the iterable sequence. Throws an error in case the iterable is empty.
The first element.
Returns new IterableWrapper<T>
which is contains intersection of this instance and another one or an Array
.
Another IterableWrapper<T>
or Array<T>
.
Function that compares two elements. If ommitted, comparison will use equality operator ===.
IterableWrapper<T>
containing intersection of these iterables or arrays.
Determines whether the iterable is empty.
true
if there are no elements in the wrapped iterable.
Returns the last element in the iterable sequence. Returns undefined
in case the iterable is empty.
Optimized if the underlying iterable is an Array
.
The last element or undefined.
Calculates lenght of the underlying iterable.
Optimized if the underlying iterable is an Array
.
Number of elements in the iterable.
Similar to Array.map
.
Creates a new IterableWrapper<T>
on top of this one.
All elements are passed to a mapper function which is supposed
to convert them and/or create another object based on the original.
Function that converts each item. Called lazily on demand.
New IterableWrapper<T>
with mapped content.
Finds maximum using a mapper function that produces a number for each element.
Function that returns a number for each element.
The biggest of all numbers returned by the mapper function. Undefined if iterable sequence is empty.
Finds minimum using a mapper function that produces a number for each element.
Function that returns a number for each element.
The smalllest of all numbers returned by the mapper function. Undefined if iterable sequence is empty.
The same functionality as Array.reduce
.
Passes all elements into a function to produce a single-value result.
Aggregated value produced by the aggregator function.
Similar to Array,reverse
.
Creates a reversed iterable sequence based on this one.
Optimized if the input iterable is an Array
. Constructs a temporary Array
in case it's other kind of iterable.
Reversed iterable IterableWrapper<T>
Checks whether two collections are the same. I.e. they have the same length and elements at equal positions.
Another iterable collectio
Equality check function. If omitted, equals operator === is applied.
Skips a given number of elements in the collection.
Optimized if the underlying collection is an Array
.
Number of skipped elements.
Another IterableWrapper<T>
based on this one without the first N elements.
Similar to Array.some
.
Evaluates whether at least one element is accepted by provided predicate.
Predicate that has to return true
to accept the passed element.
true
if at least one element is accepted. false
if none is accepted or the sequence is empty.
Similar to Array.sort
.
Out-of-place sort function. Sorts the collection and returns a new IteratorWrapper<T>
over ordered results.
Beware that this function constructs a temporary Array
that might affect performance negatively.
Comparison function (same as Array.sort
comparison function).
It has to return negative value if a < b, 0 if a === b, positive value if a > b.
Sorted sequence.
Calculates sum using a mapper funcation that produces a number for each element.
Function that returns a number for each element.
Sum of all numbers returned by mapper function.
Takes at most N elements and then stops the iteration.
Maximum number of elements.
Another IterableWrapper<T>
limited to maximum of N elements.
Returns elements in the collection as long as a condition is met.
Stops iteration when given predicate returns false
for the first time.
Predicate that accepts an element and return true
to continue / false
to stop.
New iterable that is limited by given condition.
Constructs a new Array
out of the iterable collection.
Constructs a new Map<TKey, T[]>
(built-in JavaScript object) out of all elements in the iterable collection.
Function that produces a key for each individual element.
A new Map<TKey, T[]>
.
Constructs a new ReadonlyArray
out of the iterable collection.
Note that ReadonlyArray<T>
is TypeScript-specific interface. No such object exists in JS.
It's an Array protected from writing by the TS compiler.
Constructs a new ReadonlyMap<TKey, T[]>
out of all elements in the iterable collection.
Function that produces a key for each individual element.
A new ReadonlyMap<TKey, T[]>
. ReadonlyMap is TypeScript-specific version of Map
protected from writing.
Constructs a ReadonlySet<T>
out of the iterable collection. Duplicated elements are removed.
Note that ReadonlySet<T>
is TypeScript-specific interface. No such object exists in JS.
It's a Set<T>
protected from writing by TS compiler.
ReadonlySet<T>
of unique elements in the iterable sequence.
Converts all elements into strings and joins them together into single string separated by coma or other separator.
Separator among elements
Function that converts element to text. The function may return undefined
to skip an element.
If ommitted x.toString()
is applied.
Creates Set<T>
(built-in JavaScript object) out of the iterable sequence.
Duplicated elements are removed.
Set<T>
of unique elements in the iterable sequence.
Attempts to retrieve an element at given index.
0-based index
Element at the index or undefined
if the index is out of range.
Returns the first element in the iterable sequence. Throws an error in case the iterable is empty.
The last element.
Returns the last element in the iterable sequence. Returns undefined
in case the iterable is empty.
Optimized if the underlying iterable is an Array
.
The last element or undefined.
Generated using TypeDoc
Wraps
IterableIterator<T>
to provide additional functionality. There may be performance benefits when you chain multiple calls together since the wrappedArray
is not reconstructed.Do not modify the wrapped collection as long as you are working with its wrapper object.