Home Manual Reference Source

Function

Static Public Summary
public

enumerate(iterable: Iterable, start: number): IterableIterator

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

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:

NameTypeAttributeDescription
iterable Iterable

The input iterable.

start number
  • optional
  • default: 0

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

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:

NameTypeAttributeDescription
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

Same as zip, but continues to yield zipped tuples until the last iterable is exhausted.

Params:

NameTypeAttributeDescription
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

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:

NameTypeAttributeDescription
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

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:

NameTypeAttributeDescription
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

Same as _zip, but continues to yield zipped tuples until the last iterable is exhausted.

Params:

NameTypeAttributeDescription
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' ] ) ) ;