summaryrefslogtreecommitdiff
path: root/Data/DefaultContent/Libraries/luafun/doc/indexing.rst
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-10-26 11:32:46 +0800
committerchai <chaifix@163.com>2021-10-26 11:32:46 +0800
commit0549b1e5a8a3132005e275d6026db8003cb067d2 (patch)
treef0d7751ec32ecf5c4d23997fa0ffd3450a5a755a /Data/DefaultContent/Libraries/luafun/doc/indexing.rst
parent32345800737b668011a87328cd3dcce59ec2934c (diff)
*rename folder
Diffstat (limited to 'Data/DefaultContent/Libraries/luafun/doc/indexing.rst')
-rw-r--r--Data/DefaultContent/Libraries/luafun/doc/indexing.rst74
1 files changed, 74 insertions, 0 deletions
diff --git a/Data/DefaultContent/Libraries/luafun/doc/indexing.rst b/Data/DefaultContent/Libraries/luafun/doc/indexing.rst
new file mode 100644
index 0000000..324cfbf
--- /dev/null
+++ b/Data/DefaultContent/Libraries/luafun/doc/indexing.rst
@@ -0,0 +1,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`.
+
+