Skip to content

Commit 748507a

Browse files
committed
docs(python/algorithms): update docstrings
1 parent e483936 commit 748507a

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

include/algorithms/stl.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ void SortContainer(Container &container) {
5353
* @return The number of elements that satisfy the predicate
5454
*
5555
* Counts the number of elements in the range for which the predicate returns true.
56-
* The predicate must be callable with elements of the range and return a value
57-
* convertible to bool.
56+
* The predicate must be callable with elements of the range and return a value convertible to bool.
5857
*
5958
* @code
6059
* std::vector<int> numbers{1, 2, 3, 4, 5, 6};
@@ -77,9 +76,8 @@ auto CountIf(Range &&range, Predicate predicate) -> std::size_t {
7776
* @param transform The transformation function to apply to each element
7877
* @return A vector containing the transformed elements
7978
*
80-
* Applies the transformation function to each element in the input range and
81-
* collects the results in a new vector. The transformation function must be
82-
* callable with elements of the range.
79+
* Applies the transformation function to each element in the input range and collects the results
80+
* in a new vector. The transformation function must be callable with elements of the range.
8381
*
8482
* @code
8583
* std::vector<int> numbers{1, 2, 3, 4, 5};

python/src/demo/algorithms.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717

1818

1919
def sort_inplace(data: list[T] | Container[T]) -> None:
20-
"""Sort a list or Container in place.
20+
"""Sort a container in-place.
21+
22+
Sorts the elements in the container in ascending order.
2123
2224
Parameters
2325
----------
24-
data : list[T] or Container[T]
25-
The data structure to sort
26+
data : list[T] | Container[T]
27+
The container to sort in-place
2628
2729
Examples
2830
--------
@@ -41,17 +43,20 @@ def sort_inplace(data: list[T] | Container[T]) -> None:
4143
def count_if(data: Iterable[T], predicate: Callable[[T], bool]) -> int:
4244
"""Count elements in a sequence that satisfy a predicate.
4345
46+
Counts the number of elements in the sequence for which the predicate
47+
returns true.
48+
4449
Parameters
4550
----------
4651
data : Iterable[T]
47-
The data to search through
52+
The input sequence to examine
4853
predicate : Callable[[T], bool]
49-
Function to test each element
54+
The predicate function to test each element
5055
5156
Returns
5257
-------
5358
int
54-
Number of elements matching the predicate
59+
The number of elements that satisfy the predicate
5560
5661
Examples
5762
--------
@@ -72,17 +77,20 @@ def count_if(data: Iterable[T], predicate: Callable[[T], bool]) -> int:
7277
def transform_to_list(data: Iterable[T], func: Callable[[T], U]) -> list[U]:
7378
"""Transform a sequence into a list using a transformation function.
7479
80+
Applies the transformation function to each element in the input sequence
81+
and collects the results in a new list.
82+
7583
Parameters
7684
----------
7785
data : Iterable[T]
78-
The data to transform
86+
The input sequence to transform
7987
func : Callable[[T], U]
80-
Function to apply to each element
88+
The transformation function to apply to each element
8189
8290
Returns
8391
-------
8492
list[U]
85-
List of transformed elements
93+
A list containing the transformed elements
8694
8795
Examples
8896
--------
@@ -107,13 +115,13 @@ def find_min_max(
107115
108116
Parameters
109117
----------
110-
data : Iterable[T]
111-
The sequence to search
118+
data : Iterable[SupportsRichComparisonT]
119+
The input sequence to search for minimum and maximum elements
112120
113121
Returns
114122
-------
115-
tuple[T, T]
116-
Tuple containing (minimum, maximum) values
123+
tuple[SupportsRichComparisonT, SupportsRichComparisonT]
124+
A tuple containing the minimum and maximum elements (min, max)
117125
"""
118126
match data:
119127
case list() | tuple():
@@ -127,15 +135,17 @@ def find_min_max(
127135
def pipeline(*functions: Callable[[Any], Any]) -> Callable[[Any], Any]:
128136
"""Create a function pipeline.
129137
138+
Creates a function that applies a sequence of functions in a pipeline.
139+
130140
Parameters
131141
----------
132142
*functions : Callable[[Any], Any]
133-
Functions to compose in pipeline order
143+
The functions to compose in pipeline order
134144
135145
Returns
136146
-------
137147
Callable[[Any], Any]
138-
Composed function that applies all functions in sequence
148+
A composed function that applies all functions in sequence
139149
140150
Examples
141151
--------

0 commit comments

Comments
 (0)