Module iterator

This module is an iterator that knows how to access items from the table, one at a time, keeping track of the current position in a given sequence.

Info:

  • Copyright: 2021-2022
  • Release: 1.0.0
  • License: MIT
  • Author: Denys G. Santos

Functions

key () Obtain the key for the actual iteration.
value () Obtain the value for the actual iteration.
hasNext () Check if the iterator has the next element.
next () iterate to the next element.


Functions

key ()
Obtain the key for the actual iteration. Before first and after the last iteration the result will be every nil.

Returns:

    any - the actual key

Usage:

    local table = require "ptable"
    local tbl   = table({a = 1, b = 2, c = 3})
    local it    = tbl:iterator()
    
    it:next() -- perform iteration to point counter to the first pairs element
    it:key()  -- it'll return 'a'
value ()
Obtain the value for the actual iteration. Before first and after the last iteration the result will be every nil.

Returns:

    any - the actual key

Usage:

    local table = require "ptable"
    local tbl   = table({a = 1, b = 2, c = 3})
    local it    = tbl:iterator()
    
    it:next()  -- perform iteration to point counter to the first pairs element
    it:value() -- it'll return '1'
hasNext ()
Check if the iterator has the next element.

Returns:

    boolean - true if has next, other else false

Usage:

    local table = require "ptable"
    local tbl   = table({a = 1, b = 2, c = 3})
    local it    = tbl:iterator()
    
    it:hasnext() -- it'll return true
next ()
iterate to the next element. in case of iterate more then the numbers of elements you'll receive an array index out of bound exception
generated by LDoc 1.4.6 Last updated 2021-11-24 15:47:32