1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
Indexing
========
.. module:: fun
This section contains functions to find elements by its values.
.. function:: index(x, gen, param, state)
iterator:index(x)
:param 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:
.. code-block:: lua
> print(index(2, range(0)))
nil
> print(index("b", {"a", "b", "c", "d", "e"}))
2
.. function:: index_of(x, gen, param, state)
iterator:index_of(x)
An alias for :func:`index`.
.. function:: elem_index(x, gen, param, state)
iterator:elem_index(x)
An alias for :func:`index`.
.. function:: indexes(x, gen, param, state)
iterator:indexes(x)
:param 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:
.. code-block:: lua
> each(print, indexes("a", {"a", "b", "c", "d", "e", "a", "b", "a", "a"}))
1
6
9
10
.. seealso:: :func:`filter`
.. function:: indices(x, gen, param, state)
iterator:indices(x)
An alias for :func:`indexes`.
.. function:: elem_indexes(x, gen, param, state)
iterator:elem_indexes(x)
An alias for :func:`indexes`.
.. function:: elem_indices(x, gen, param, state)
iterator:elem_indices(x)
An alias for :func:`indexes`.
|