Constructor
new Generator(data, next) → {Generator}
- Source:
Parameters:
Name | Type | Description |
---|---|---|
data |
Any | |
next |
Method() |
Returns:
- Type
- Generator
Methods
(static) has_next() → {Bool}
- Source:
Returns false when Iterator is exhausted.
Returns:
- Type
- Bool
(static) __iter() → {Iterator}
- Source:
- See:
-
- iter
Return self
Returns:
- Type
- Iterator
(static) next() → {Any}
- Source:
returns the next yielded element. If Iterator is exhausted, returns undefined.
Example
var data = iter( "ABCD" );
while( data.has_next() {
data.next(); --> "A", "B", "C", "D"
}
Returns:
- Type
- Any
(static) compress(selectorsopt) → {Iterator}
- Source:
Make an iterator that filters elements from iterable returning only those that have a corresponding element in selectors that evaluates to True. Stops when either the data or selectors iterables has been exhausted.
Example
iter( "ABCDEF" ).compress( [ 1, 0, 1, 0, 1, 1 ] ) --> "A", "C", "E", "F"
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
selectors |
Iterable |
<optional> |
Returns:
Yields matching elements.
- Type
- Iterator
(static) filter(functionopt) → {Iterator}
- Source:
Construct an iterator from those elements of iterable for which function returns true.
Example
irange( 10 ).filter( function( x ) { return x % 2 } ) --> 1, 3, 5, 7, 9
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
function |
Method(e) |
<optional> |
Returns:
Yields elements from iterable for which function returns true.
- Type
- Iterator
(static) filter_false(functionopt) → {Iterator}
- Source:
Construct an iterator from those elements of iterable for which function returns false.
Example
irange( 10 ).filter_false( function( x ) { return x % 2 } ) --> 0, 2, 4, 6, 8
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
function |
Method |
<optional> |
Returns:
Yields elements from iterable for which function returns false.
- Type
- Iterator
(static) group_by(keyopt) → {Iterator}
- Source:
Make an iterator that returns consecutive keys and groups from the iterable.
Example
iter_take( 2, iter( "AAAABBBCCDAABBB" ).group_by() ) --> { key: "A", group: [ "A", "A", "A", "A" ] }, { key: "B", group: [ "B", "B", "B" ] }
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
key |
Method |
<optional> |
Function computing a key value for each element. If not specified or is undefined, key defaults to an identity function and returns the element unchanged. Generally, the iterable needs to already be sorted on the same key function. |
Returns:
Yields struct with key and array group for each group.
- Type
- Iterator
(static) map(function) → {Iterator}
- Source:
Return an iterator that applies function to every item of iterable, yielding the results.
Example
iter( [ 2, 3, 10 ] ).map( function( x ) { return x * x; } ) --> 4, 9, 100
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
function |
Method | ||
... |
Iterable |
<optional> |
Returns:
Yields result of passing an emement of every argument into a function.
- Type
- Iterator
(static) slice(iterable, startopt, stop, stepopt) → {Iterator}
- Source:
Make an iterator that returns selected elements from the iterable. If start is non-zero, then elements from the iterable are skipped until start is reached. Afterward, elements are returned consecutively unless step is set higher than one which results in items being skipped. If stop is undefined, then iteration continues until the iterator is exhausted, if at all; otherwise, it stops at the specified position.
Example
iter( "ABCDEFG" ).slice( 2 ) --> "A", "B"
iter( "ABCDEFG" ).slice( 2, 4 ) --> "C", "D"
iter( "ABCDEFG" ).slice( 2, undefined ) --> "C", "D", "E", "F", "G"
iter( "ABCDEFG" ).slice( 0, undefined, 2 ) --> "A", "C", "E", "G"
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
iterable |
Iterable | |||
start |
Number |
<optional> |
0
|
|
stop |
Number | |||
step |
Number |
<optional> |
1
|
Returns:
Yields only elements from range.
- Type
- Iterator