diff --git a/CHANGELOG.md b/CHANGELOG.md index aea11df90995b3695feef197ca9957cabc73d73b..b8e0518e0fdacd6f62834f429abd3a0266fe105f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # v2.25.8 * fixed the modules page in documentation +* added choose_with_index # v2.25.7 diff --git a/docs/coding/sequences.rst b/docs/coding/sequences.rst index 777cd9ad5ac2fb75e715e31fc114174e33a76fb7..d0e9f8becc405dd0f36bb13c62f1d9812c9989ff 100644 --- a/docs/coding/sequences.rst +++ b/docs/coding/sequences.rst @@ -1,6 +1,5 @@ -======================= Sequences and iterators -======================= +####################### Rolling averages ================ @@ -42,22 +41,21 @@ iterate_callable .. autofunction:: satella.coding.sequences.iterate_callable -choose ------- +Choosing stuff +-------------- To return the first single element that returns true on given callable, use the following function: .. autofunction:: satella.coding.sequences.choose -choose_one ----------- - -Does the same thing as choose, but exhausts the generator and checks if there are no multiple -elements matching the callable. If there are, raises ValueError. +If you need to exhaust the generator, use the following: .. autofunction:: satella.coding.sequences.choose_one +If you needn an index of the element found, use: + +.. autofunction:: satella.coding.sequences.choose_with_index AlreadySeen ----------- @@ -115,7 +113,7 @@ take_n For the rare moments, when you wish you could just do: -:: +.. code-block:: python iterator: tp.Iterator[T] = iterator n_elements: tp.List[T] = iterator[:n] @@ -125,7 +123,6 @@ However, this function comes to the rescue: .. autofunction:: satella.coding.sequences.take_n - infinite_iterator ----------------- @@ -139,7 +136,7 @@ A factory for filter functions that check if given object is an instance of something (or multiple classes, if passed a tuple of classes). Use like that -:: +.. code-block:: python orders: tp.List[BaseOrder] = ... read_orders = filter(is_instance(ReadOrder), orders) @@ -206,7 +203,7 @@ zip_shifted .. autofunction:: satella.coding.sequences.zip_shifted -This is deprecated. Use ``zip(shift(...))`` instead. +This is deprecated. Use :code:`zip(shift(...))`` instead. stop_after