Indexing¶
This section contains functions to find elements by its values.
- fun.index(x, gen, param, state)¶
- iterator:index(x)
- Parameters
x – a value to find
- Returns
the position of the first element that equals to the x
The function returns the position of the first element in the given iterator which is equal (using
==
) to the query element, ornil
if there is no such element.Examples:
> print(index(2, range(0))) nil > print(index("b", {"a", "b", "c", "d", "e"})) 2
- fun.indexes(x, gen, param, state)¶
- iterator:indexes(x)
- Parameters
x – a value to find
- Returns
an iterator which positions of elements that equal to the x
The function returns an iterator to positions of elements which equals to the query element.
Examples:
> each(print, indexes("a", {"a", "b", "c", "d", "e", "a", "b", "a", "a"})) 1 6 9 10
See also