Iter type

Iterator. Parent type for all specific iterator types.

Direct children types

ArrIter
Arr (array) iterator.
ConstIter
Iterator that returns given value forever.
FilterIter
EXPERIMENTAL! Do not use!
FunIter
EXPERIMENTAL! Do not use!
HashIter
EXPERIMENTAL Hash iterator.
MapIter
EXPERIMENTAL! Do not use!
RangeIter
Iterates over a Range
RecIter
Recursively iterates x. Depth-first-search (DFS), pre-order (NLR). See https://en.wikipedia.org/wiki/Tree_traversal

Constructors

Iter(i:Iter) Source: autoload/globals/Iter.ngs:89
Supports "for i in existing_iterator". Useful if you want to have a reference to the Iter for any reason.

Automatically called by NGS for syntax

for my_var in something { ... }

Returns

i

Example

# Prints 0, 2, ...
for i in my_iter=Iter(10) {
  echo(i)
  my_iter.drop(1)
}
Iter(f:Fun) Source: autoload/globals/Iter.ngs:192
Undocumented
Iter(r:NumRange) Source: autoload/globals/Iter.ngs:243
Create Iter from NumRange
Iter(n:Int) Source: autoload/globals/Iter.ngs:246
Create Iter from Int
Iter(arr:Arr) Source: autoload/globals/Iter.ngs:287
Calls ArrIter constructor.

Returns

ArrIter

Example

i = Iter([10, 20, 30])
Iter(h:Hash) Source: autoload/globals/Iter.ngs:328
Undocumented
Iter(s:Set) Source: autoload/globals/Iter.ngs:368
Iterator for Set. Currently implemented as ArrIter for the Set elements.

Returns

ArrIter
Iter(s:SubSeq) Source: autoload/globals/Iter.ngs:479
Iterator over elements of the subsequence

Returns

Iter
Iter(rd:ResDef) Source: autoload/globals/Res.ngs:113
EXPERIMENTAL! Do not use!

Methods

drop(i:Iter, n:Int) Source: autoload/globals/Iter.ngs:74
Fetch and drop next n values from iterator i.

Example

i = Iter([10,20,30])
drop(i, 1)
echo(i.next())
# Output: 20
each(i:Iter, cb:Fun) Source: autoload/globals/Iter.ngs:95
Calls cb with each element from i

Returns

i

Example

Iter(10).each(echo)  # Prints 0 to 9
filter(i:Iter, pattern:Any) Source: autoload/globals/Iter.ngs:183
EXPERIMENTAL! Do not use!
init(i:MapIter, upstream_iter:Iter, mapper:Fun) Source: autoload/globals/Iter.ngs:113
EXPERIMENTAL! Do not use!
init(i:FilterIter, upstream_iter:Iter, pattern:Any) Source: autoload/globals/Iter.ngs:136
EXPERIMENTAL! Do not use!
JsonData(i:Iter) Source: autoload/globals/Iter.ngs:439
Convert Iter into JSON compatible data structure - array. Forces evaluation of MapIter for example.
map(i:Iter, mapper:Fun) Source: autoload/globals/Iter.ngs:129
EXPERIMENTAL! Do not use!
nextv(i:Iter) Source: autoload/globals/Iter.ngs:106
Calls cb with each value from i. Same as next(i) except for key-value containers, where next() returns [key, value] but nextv() returns value.
reject(i:Iter, pattern:Any) Source: autoload/globals/Iter.ngs:185
EXPERIMENTAL! Do not use!
skip(i:Iter, pattern:Any=method) Source: autoload/globals/Iter.ngs:443
Returns the given Iter but skipping leading elements while the pattern matches. If all elements match the pattern, the Iter will be empty. Default pattern skips leading truthy elements (stops at first falsy).

Returns

Iter

Example

[1, 2, null, 3].Iter().skip().Arr() == [null, 3]
[0, 2, 3, 25, 19, 7].Iter().skip(X != 3).Arr() == [3, 25, 19, 7]
skip(i:Iter, count:Int) Source: autoload/globals/Iter.ngs:465
Returns the given Iter after consuming first count elements.

Returns

Iter

Example

[3, 4, 5, 34, 5].Iter().skip(3).Arr() == [34, 5] 
take(i:Iter, n:Int) Source: autoload/globals/Iter.ngs:79
Fetch and convert to array next n values from iterator i.

Example

i = Iter([10,20,30])
echo(i.take(2))  # Output: [10,20]
throw_if_no_next(i:Iter) Source: autoload/globals/Iter.ngs:66
Private method of Iter.ngs, will be hidden in future.