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, or nil if there is no such element.

Examples:

> print(index(2, range(0)))
nil

> print(index("b", {"a", "b", "c", "d", "e"}))
2
fun.index_of(x, gen, param, state)
iterator:index_of(x)

An alias for index().

fun.elem_index(x, gen, param, state)
iterator:elem_index(x)

An alias for index().

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

filter()

fun.indices(x, gen, param, state)
iterator:indices(x)

An alias for indexes().

fun.elem_indexes(x, gen, param, state)
iterator:elem_indexes(x)

An alias for indexes().

fun.elem_indices(x, gen, param, state)
iterator:elem_indices(x)

An alias for indexes().