Function
Static Public Summary | ||
public |
Yields (index,element) tuples where the elements are taken from the input iterable. |
|
public |
zip(iterables: ...Iterable): IterableIterator Zips iterables together. |
|
public |
ziplongest(fillvalue: any, iterables: ...Iterable): IterableIterator Same as zip, but continues to yield zipped tuples until the last iterable is exhausted. |
Static Private Summary | ||
private |
* _zip(iterables: Iterable[]): IterableIterator Zips iterables together. |
|
private |
* _zip2(A: Iterable, B: Iterable): IterableIterator Zips exactly two iterables together. |
|
private |
* _ziplongest(fillvalue: any, iterables: Iterable[]): IterableIterator Same as _zip, but continues to yield zipped tuples until the last iterable is exhausted. |
Static Public
public enumerate(iterable: Iterable, start: number): IterableIterator source
import enumerate from '@iterable-iterator/zip/src/enumerate.js'
Yields (index,element) tuples where the elements are taken from the input
iterable. You can choose the starting index. The starting index is
0
by default.
Params:
Name | Type | Attribute | Description |
iterable | Iterable | The input iterable. |
|
start | number |
|
The starting index. |
Return:
IterableIterator |
Example:
// returns [ [ 0 , 'a' ] , [ 1 , 'b' ] , [ 2 , 'c' ] ]
list( enumerate( 'abc' ) ) ;
// returns [ [ 1 , 'a' ] , [ 2 , 'b' ] , [ 3 , 'c' ] ]
list( enumerate( 'abc' , 1 ) ) ;
public zip(iterables: ...Iterable): IterableIterator source
import zip from '@iterable-iterator/zip/src/zip.js'
Zips iterables together. Yields a tuple containing the first element of each iterable, then a tupe containing the second element of each iterable, etc. Stops when one of the iterables runs out of elements.
Params:
Name | Type | Attribute | Description |
iterables | ...Iterable | The iterables to zip. |
Return:
IterableIterator |
Example:
// returns [ [ 'a' , 1 ] , [ 'b' , 2 ] , [ 'c' , 3 ] ]
list( zip( 'abcd' , range(3) ) ) ;
public ziplongest(fillvalue: any, iterables: ...Iterable): IterableIterator source
import ziplongest from '@iterable-iterator/zip/src/ziplongest.js'
Same as zip, but continues to yield zipped tuples until the last iterable is exhausted.
Params:
Name | Type | Attribute | Description |
fillvalue | any | The value to yield for iterators that are exhausted. |
|
iterables | ...Iterable | The iterables to zip. |
Return:
IterableIterator |
Example:
// returns [['A','x'],['B','y'],['C','-'],['D','-']]
list( ziplongest( '-' , 'ABCD', 'xy' ) ) ;
Static Private
private * _zip(iterables: Iterable[]): IterableIterator source
import _zip from '@iterable-iterator/zip/src/_zip.js'
Zips iterables together. Yields a tuple containing the first element of each iterable, then a tupe containing the second element of each iterable, etc. Stops when one of the iterables runs out of elements.
Params:
Name | Type | Attribute | Description |
iterables | Iterable[] | The iterables to zip. |
Return:
IterableIterator |
Example:
// returns [ [ 'a' , 1 ] , [ 'b' , 2 ] , [ 'c' , 3 ] ]
list( _zip( [ 'abcd' , range(3) ] ) ) ;
private * _zip2(A: Iterable, B: Iterable): IterableIterator source
import _zip2 from '@iterable-iterator/zip/src/_zip2.js'
Zips exactly two iterables together. Yields a tuple containing the first element of each iterable, then a tupe containing the second element of each iterable, etc. Stops when one of the two iterables runs out of elements.
Params:
Name | Type | Attribute | Description |
A | Iterable | The first iterable. |
|
B | Iterable | The second iterable. |
Return:
IterableIterator |
Example:
// returns [ [ 'a' , 1 ] , [ 'b' , 2 ] , [ 'c' , 3 ] ]
list( _zip2( 'abcd' , range(1, 4) ) ) ;
private * _ziplongest(fillvalue: any, iterables: Iterable[]): IterableIterator source
import _ziplongest from '@iterable-iterator/zip/src/_ziplongest.js'
Same as _zip, but continues to yield zipped tuples until the last iterable is exhausted.
Params:
Name | Type | Attribute | Description |
fillvalue | any | The value to yield for iterators that are exhausted. |
|
iterables | Iterable[] | The iterables to zip. |
Return:
IterableIterator |
Example:
// returns [['A','x'],['B','y'],['C','-'],['D','-']]
list( _ziplongest( '-' , [ 'ABCD', 'xy' ] ) ) ;