Constructor
new Iterator(data, next, has_next) → {Iterator}
- Source:
Parameters:
Name | Type | Description |
---|---|---|
data |
Any | |
next |
Method() | |
has_next |
Method() |
Returns:
- Type
- Iterator
Extends
Methods
(static) has_next() → {Bool}
- Source:
Returns true when Iterator is exhausted.
Returns:
- Type
- Bool
(static) combinations(ropt) → {Iterator}
- Source:
Make an iterator that yields r length subsequences of elements from the iterable.
Example
irange( 4 ).combinations( 3 ) --> [ 0, 1, 2 ], [ 0, 1, 3 ], [ 0, 2, 3 ], [ 1, 2, 3 ]
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
r |
Number |
<optional> |
Returns:
- Type
- Iterator
(static) combinations_with_replacements(ropt) → {Iterator}
- Source:
Make an iterator that yields r length subsequences of the iterable allowing individual elements to be repeated more than once.
Example
irange( 3 ).combinations_with_replacements( 2 ) --> [ 0, 0 ], [ 0, 1 ], [ 0, 2 ], [ 1, 1 ], [ 1, 2 ], [ 2, 2 ]
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
r |
Number |
<optional> |
Returns:
- Type
- Iterator
(static) permutations(ropt) → {Iterator}
- Source:
Return an iterator that yields r length permutations.
Example
irange( 3 ).permutations( 2 ) --> [ 0,1 ], [ 0,2 ], [ 1,0 ], [ 1,2 ], [ 2,0 ], [ 2,1 ]
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
r |
Number |
<optional> |
If r is not specified or is indefined, then r defaults to the length of the iterable and all possible full-length permutations are generated. |
Returns:
- Type
- Iterator
(static) product(repeats) → {Iterator}
- Source:
Return an iterator that yields Cartesian product of items from this Iterator with itself repeats times.
Example
iter( [ 0, 1 ] ).product( 3 ) --> [ 0, 0, 0 ], [ 0, 0, 1 ], [ 0, 1, 0 ], [ 0, 1, 1 ], [ 1, 0, 0 ] ...
Parameters:
Name | Type | Description |
---|---|---|
repeats |
Number |
Returns:
- Type
- Iterator
(static) reduce(function, Anyopt) → {Any}
- Source:
Apply function of two arguments cumulatively to the items of Iterator, from left to right, so as to reduce it to a single value.
Example
iter( [ 1, 2, 3, 4 ] ).reduce( function( _a, _x ) { return _a + _x; } ) --> 10
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
function |
Method(a,x) | ||
Any |
<optional> |
initializer |
Returns:
- Type
- Any
(static) sorted(keyopt, reverseopt)
- Source:
Returns a new Iterator that yields items in iterable sorted
Example
iter( [ 5, 2, 3, 1, 4 ] ).sorted() --> 1, 2, 3, 4, 5
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
key |
Method |
<optional> |
||
reverse |
Bool |
<optional> |
false
|
(static) to_array() → {Array}
- Source:
Exhausts iterator and combines all of its elements into an array
Example
iter( "1234" ).to_array() --> [ "1", "2", "3", "4" ]
Returns:
- Type
- Array
(static) to_string(separatoropt) → {String}
- Source:
Exhausts iterator and combines all of its elements into a string.
Example
iter( [ 1, 2, 3, 4 ] ).to_string() --> "1234"
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
separator |
String |
<optional> |
""
|
Returns:
- Type
- String
(static) unique(keyopt) → {Iterator}
- Source:
Returns a new Iterator that yields non-repeating items from sorted iterable
Example
iter( "abcacbacbacbac" ).unique().to_string() --> "abc"
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
key |
Method |
<optional> |
true
|
Returns:
- Type
- Iterator