Skip to content

Commit cc9b295

Browse files
committed
Various documentation fixes in stdlib modules
* gb_sets * lists * ordsets * queue * sets
1 parent d2a5292 commit cc9b295

5 files changed

Lines changed: 61 additions & 77 deletions

File tree

lib/stdlib/src/gb_sets.erl

Lines changed: 27 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ of one set is also a member of the other set; otherwise, returns `false`.
207207
```erlang
208208
1> Empty = gb_sets:new().
209209
2> S = gb_sets:from_list([a,b]).
210-
3> gb_sets:is_equal(S, S)
210+
3> gb_sets:is_equal(S, S).
211211
true
212-
4> gb_sets:is_equal(S, Empty)
212+
4> gb_sets:is_equal(S, Empty).
213213
false
214214
```
215215
""".
@@ -380,7 +380,7 @@ does not rebalance the tree.
380380
## Examples
381381

382382
```erlang
383-
1> S0 = gb_sets:from_ordset(lists:seq(1, 100)).
383+
1> S0 = gb_sets:from_list(lists:seq(1, 100)).
384384
2> Delete = fun(E, Set) -> gb_sets:delete(E, Set) end.
385385
3> S1 = lists:foldl(Delete, S0, lists:seq(1, 50)).
386386
4> gb_sets:size(S1).
@@ -460,7 +460,7 @@ contain duplicates.
460460
## Examples
461461

462462
```erlang
463-
1> Unordered = [x,y,a,x,y,b,b,z]
463+
1> Unordered = [x,y,a,x,y,b,b,z].
464464
2> gb_sets:to_list(gb_sets:from_list(Unordered)).
465465
[a,b,x,y,z]
466466
```
@@ -797,10 +797,10 @@ The implementation is very efficient; traversing the whole set using
797797
[`next/1`](`next/1`) is only slightly slower than getting the list of
798798
all elements using `to_list/1` and traversing that. The main advantage
799799
of the iterator approach is that it avoids building the complete list
800-
of all elements to be built in memory at once.
800+
of all elements in memory at once.
801801

802802
```erlang
803-
1> S = gb_sets:from_ordset([1,2,3,4,5]).
803+
1> S = gb_sets:from_list([1,2,3,4,5]).
804804
2> Iter0 = gb_sets:iterator(S, ordered).
805805
3> element(1, gb_sets:next(Iter0)).
806806
1
@@ -837,25 +837,7 @@ iterator_r({_, _, R} = T, As) ->
837837
iterator_r(nil, As) ->
838838
As.
839839

840-
-doc """
841-
Returns an iterator that can be used for traversing the entries of `Set`; see
842-
`next/1`.
843-
844-
Unlike the iterator returned by `iterator/1` or `iterator/2`, this
845-
iterator starts with the first element greater than or equal to
846-
`Element`.
847-
848-
Equivalent to [`iterator_from(Element, Set, ordered)`](`iterator_from/3`).
849-
850-
## Examples
851-
852-
```erlang
853-
1> S = gb_sets:from_ordset([10,20,30,40,50]).
854-
2> Iter = gb_sets:iterator_from(17, S).
855-
3> element(1, gb_sets:next(Iter)).
856-
20
857-
```
858-
""".
840+
-doc(#{equiv => iterator_from(Element, Set, ordered)}).
859841
-doc(#{since => <<"OTP 18.0">>}).
860842
-spec iterator_from(Element, Set) -> Iter when
861843
Set :: set(Element),
@@ -865,19 +847,19 @@ iterator_from(Element, Set) ->
865847
iterator_from(Element, Set, ordered).
866848

867849
-doc """
868-
Returns an iterator that can be used for traversing the entries of `Set`; see
869-
`next/1`.
870-
871-
Unlike the iterator returned by `iterator/1` or `iterator/2`, this
872-
iterator starts with the first element greater than or equal to
873-
`Element`.
850+
Returns an iterator over members of `Set` in the given `Order`, starting
851+
from `Element` or, if absent, the first member that follows in the
852+
iteration order, if any; see `next/1`.
874853

875854
## Examples
876855

877856
```erlang
878-
1> S = gb_sets:from_ordset([10,20,30,40,50]).
879-
2> Iter = gb_sets:iterator_from(17, S, reversed).
880-
3> element(1, gb_sets:next(Iter)).
857+
1> S = gb_sets:from_list([10,20,30,40,50]).
858+
2> Iter1 = gb_sets:iterator_from(17, S, ordered).
859+
3> element(1, gb_sets:next(Iter1)).
860+
20
861+
4> Iter2 = gb_sets:iterator_from(17, S, reversed).
862+
5> element(1, gb_sets:next(Iter2)).
881863
10
882864
```
883865
""".
@@ -916,7 +898,7 @@ by iterator `Iter1`, and `Iter2` is the new iterator to be used for traversing
916898
the remaining elements, or the atom `none` if no elements remain.
917899

918900
```erlang
919-
1> S = gb_sets:from_ordset([1,2,3,4,5]).
901+
1> S = gb_sets:from_list([1,2,3,4,5]).
920902
2> Iter0 = gb_sets:iterator(S).
921903
3> {Element0, Iter1} = gb_sets:next(Iter0).
922904
4> Element0.
@@ -955,8 +937,8 @@ next({_, []}) ->
955937
%% If the sets are not very different in size, i.e., if |Y| / |X| >= c *
956938
%% log(|Y|), then the fastest way to do union (and the other similar set
957939
%% operations) is to build the lists of elements, traverse these lists
958-
%% in parallel while building a reversed ackumulator list, and finally
959-
%% rebuild the tree directly from the ackumulator. Other methods of
940+
%% in parallel while building a reversed accumulator list, and finally
941+
%% rebuild the tree directly from the accumulator. Other methods of
960942
%% traversing the elements can be devised, but they all have higher
961943
%% overhead.
962944

@@ -1035,7 +1017,7 @@ union_1([], S) ->
10351017
%% that the same is likely to apply to the next element also,
10361018
%% statistically reducing the number of failed tests and automatically
10371019
%% adapting to cases of lists having very different lengths. This saves
1038-
%% 10-40% of the traversation time compared to a "fixed" strategy,
1020+
%% 10-40% of the traversal time compared to a "fixed" strategy,
10391021
%% depending on the sizes and contents of the lists.
10401022
%%
10411023
%% 3) A tail recursive version using `lists:reverse/2' is about 5-10%
@@ -1092,15 +1074,15 @@ all sets, without duplicates.
10921074
```erlang
10931075
1> S0 = gb_sets:from_list([a,b,c,d]).
10941076
2> S1 = gb_sets:from_list([d,e,f]).
1095-
3> S2 = gb_sets:from_list([q,r])
1077+
3> S2 = gb_sets:from_list([q,r]).
10961078
4> Sets = [S0, S1, S2].
10971079
5> Union = gb_sets:union(Sets).
10981080
6> gb_sets:to_list(Union).
10991081
[a,b,c,d,e,f,q,r]
11001082
```
11011083
""".
11021084
-spec union(SetList) -> Set when
1103-
SetList :: [set(Element),...],
1085+
SetList :: [set(Element)],
11041086
Set :: set(Element).
11051087

11061088
union([S | Ss]) ->
@@ -1194,7 +1176,7 @@ elements that are present in all sets.
11941176
```erlang
11951177
1> S0 = gb_sets:from_list([a,b,c,d]).
11961178
2> S1 = gb_sets:from_list([d,e,f]).
1197-
3> S2 = gb_sets:from_list([q,r])
1179+
3> S2 = gb_sets:from_list([q,r]).
11981180
4> Sets = [S0, S1, S2].
11991181
5> gb_sets:to_list(gb_sets:intersection([S0, S1, S2])).
12001182
[]
@@ -1221,15 +1203,15 @@ Returns `true` if `Set1` and `Set2` are disjoint; otherwise, returns
12211203

12221204
Two sets are disjoint if they have no elements in common.
12231205

1224-
This function is equivalent to `gb_sets:intersection(Set1, Set2) =:= []`,
1206+
This function is equivalent to `gb_sets:is_empty(gb_sets:intersection(Set1, Set2))`,
12251207
but faster.
12261208

12271209
## Examples
12281210

12291211
```erlang
12301212
1> S0 = gb_sets:from_list([a,b,c,d]).
12311213
2> S1 = gb_sets:from_list([d,e,f]).
1232-
3> S2 = gb_sets:from_list([q,r])
1214+
3> S2 = gb_sets:from_list([q,r]).
12331215
4> gb_sets:is_disjoint(S0, S1).
12341216
false
12351217
5> gb_sets:is_disjoint(S1, S2).
@@ -1493,13 +1475,13 @@ value, with `true` being equivalent to `{true, Elem}`.
14931475

14941476
```erlang
14951477
filtermap(Fun, Set1) ->
1496-
gb_sets:from_list(lists:filtermap(Fun, Set1)).
1478+
gb_sets:from_list(lists:filtermap(Fun, gb_sets:to_list(Set1))).
14971479
```
14981480

14991481
## Examples
15001482

15011483
```erlang
1502-
1> S = gb_sets:from_list([2,4,5,6,8,9])
1484+
1> S = gb_sets:from_list([2,4,5,6,8,9]).
15031485
2> F = fun(X) ->
15041486
case X rem 2 of
15051487
0 -> {true, X div 2};

lib/stdlib/src/lists.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ starting at `N+1` and continuing to the end of the list.
342342
""".
343343
-spec nthtail(N, List) -> Tail when
344344
N :: non_neg_integer(),
345-
List :: [T,...],
345+
List :: [T],
346346
Tail :: [T],
347347
T :: term().
348348

@@ -1894,7 +1894,7 @@ sort(Fun, [X, Y | T]) ->
18941894
-doc """
18951895
Returns a sorted list formed by merging `List1` and `List2` based on `Fun`.
18961896

1897-
Both `List1` and`List2` must be sorted according to the
1897+
Both `List1` and `List2` must be sorted according to the
18981898
[ordering function](`m:lists#ordering_function`) `Fun` before evaluating this
18991899
function.
19001900

@@ -2682,7 +2682,7 @@ Combines the operations of `map/2` and `foldr/3` into one pass.
26822682
> #### Note {: .info }
26832683
>
26842684
> Unless the order in which the elements are accumulated is important,
2685-
> prefer [`mapfoldl/3`](`mapfoldl/3`) as it is slighly more efficient.
2685+
> prefer [`mapfoldl/3`](`mapfoldl/3`) as it is slightly more efficient.
26862686
26872687
## Examples
26882688

lib/stdlib/src/ordsets.erl

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ Returns a new empty ordered set.
6060
## Examples
6161

6262
```erlang
63-
1> ordsets:new()
63+
1> ordsets:new().
6464
[]
6565
```
6666
""".
67-
-spec new() -> [].
67+
-spec new() -> ordset(none()).
6868

6969
new() -> [].
7070

@@ -146,9 +146,9 @@ of one set is also a member of the other set; otherwise, returns `false`.
146146
```erlang
147147
1> Empty = ordsets:new().
148148
2> S = ordsets:from_list([a,b]).
149-
3> ordsets:is_equal(S, S)
149+
3> ordsets:is_equal(S, S).
150150
true
151-
4> ordsets:is_equal(S, Empty)
151+
4> ordsets:is_equal(S, Empty).
152152
false
153153
```
154154
""".
@@ -305,7 +305,7 @@ all sets, without duplicates.
305305
```erlang
306306
1> S0 = ordsets:from_list([a,b,c,d]).
307307
2> S1 = ordsets:from_list([d,e,f]).
308-
3> S2 = ordsets:from_list([q,r])
308+
3> S2 = ordsets:from_list([q,r]).
309309
4> Sets = [S0, S1, S2].
310310
5> ordsets:union(Sets).
311311
[a,b,c,d,e,f,q,r]
@@ -363,7 +363,7 @@ elements that are present in all sets.
363363
```erlang
364364
1> S0 = ordsets:from_list([a,b,c,d]).
365365
2> S1 = ordsets:from_list([d,e,f]).
366-
3> S2 = ordsets:from_list([q,r])
366+
3> S2 = ordsets:from_list([q,r]).
367367
4> Sets = [S0, S1, S2].
368368
5> ordsets:intersection([S0, S1, S2]).
369369
[]
@@ -391,8 +391,7 @@ returns `false`.
391391

392392
Two sets are disjoint if they have no elements in common.
393393

394-
This function is equivalent to `ordsets:intersection(Ordset1, Ordset2)
395-
=:= []`, but faster.
394+
This function is equivalent to `ordsets:is_empty(ordsets:intersection(Ordset1, Ordset2))`, but faster.
396395

397396
## Examples
398397

@@ -555,13 +554,13 @@ value, with `true` being equivalent to `{true, Elem}`.
555554

556555
```erlang
557556
filtermap(Fun, Ordset1) ->
558-
ordsets:from_list(lists:filtermap(Fun, Ordset1)).
557+
ordsets:from_list(lists:filtermap(Fun, ordsets:to_list(Ordset1))).
559558
```
560559

561560
## Examples
562561

563562
```erlang
564-
1> S = ordsets:from_list([2,4,5,6,8,9])
563+
1> S = ordsets:from_list([2,4,5,6,8,9]).
565564
2> F = fun(X) ->
566565
case X rem 2 of
567566
0 -> {true, X div 2};
@@ -574,7 +573,7 @@ filtermap(Fun, Ordset1) ->
574573
""".
575574
-doc(#{since => <<"OTP 27.0">>}).
576575
-spec filtermap(Fun, Ordset1) -> Ordset2 when
577-
Fun :: fun((Element1 :: T1) -> boolean | ({true, Element2 :: T2})),
576+
Fun :: fun((Element1 :: T1) -> boolean() | {true, Element2 :: T2}),
578577
Ordset1 :: ordset(T1),
579578
Ordset2 :: ordset(T1 | T2).
580579

lib/stdlib/src/queue.erl

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ new() -> {[],[]}. %{RearList,FrontList}
123123
-doc """
124124
Tests if `Term` is a queue and returns `true` if so, otherwise `false`. Note
125125
that the test will return `true` for a term coinciding with the representation
126-
of a queue, even when not constructed by thus module. See also note on
126+
of a queue, even when not constructed by this module. See also note on
127127
[data types](`e:system:data_types.md#no_user_types`).
128128
""".
129129
-doc(#{group => <<"Original API">>}).
@@ -161,9 +161,11 @@ the queue becomes the head of the list.
161161
_Example:_
162162

163163
```erlang
164-
1> Queue = queue:from_list([1,2,3,4,5]).
164+
1> List = [1, 2, 3, 4, 5].
165+
[1,2,3,4,5]
166+
2> Queue = queue:from_list(List).
165167
{[5,4,3],[1,2]}
166-
2> List == queue:to_list(Queue).
168+
3> List =:= queue:to_list(Queue).
167169
true
168170
```
169171
""".
@@ -472,7 +474,7 @@ _Example:_
472474
```erlang
473475
1> Queue = queue:from_list([1,2,3,4,5]).
474476
{[5,4,3],[1,2]}
475-
2> Queue = queue:drop(Queue).
477+
2> Queue1 = queue:drop(Queue).
476478
{[5,4,3],[2]}
477479
3> queue:to_list(Queue1).
478480
[2,3,4,5]
@@ -507,7 +509,7 @@ _Example:_
507509
```erlang
508510
1> Queue = queue:from_list([1,2,3,4,5]).
509511
{[5,4,3],[1,2]}
510-
2> Queue = queue:drop_r(Queue).
512+
2> Queue1 = queue:drop_r(Queue).
511513
{[4,3],[1,2]}
512514
3> queue:to_list(Queue1).
513515
[1,2,3,4]
@@ -620,7 +622,7 @@ split_r1_to_f2(N, [X|R1], F1, R2, F2) ->
620622
%% filter, or rather filtermap with insert, traverses in queue order
621623
%%
622624
%% Fun(_) -> List: O(length(List) * len(Q))
623-
%% else: O(len(Q)
625+
%% else: O(len(Q))
624626
-doc """
625627
Returns a queue `Q2` that is the result of calling `Fun(Item)` on all items in
626628
`Q1`.
@@ -721,16 +723,16 @@ queue element at this position is replaced with `NewItem` in the result queue.
721723
_Example 1:_
722724

723725
```erlang
724-
1> Queue = queue:from_list([1,2,3,4,5]).
726+
1> Queue = queue:from_list([1, 2, 3, 4, 5]).
725727
{[5,4,3],[1,2]}
726728
2> Queue1 = queue:filtermap(fun (E) -> E > 2 end, Queue).
727729
{[5],[3,4]}
728730
3> queue:to_list(Queue1).
729731
[3,4,5]
730-
4> Queue1 = queue:filtermap(fun (E) -> {true, E+100} end, Queue).
731-
{"ihg","ef"}
732-
5> queue:to_list(Queue1).
733-
"efghi
732+
4> Queue2 = queue:filtermap(fun (E) -> {true, E - 100} end, Queue).
733+
{[-95,-96,-97],[-99,-98]}
734+
5> queue:to_list(Queue2).
735+
[-99,-98,-97,-96,-95]
734736
```
735737
""".
736738
-doc(#{group => <<"Original API">>,since => <<"OTP 24.0">>}).
@@ -956,7 +958,7 @@ _Example:_
956958

957959
```erlang
958960
1> Queue = queue:from_list([100,1,2,3,4,5]).
959-
2> Queue1 = queue:delete_with(fun (E) -> E > 0, Queue).
961+
2> Queue1 = queue:delete_with(fun (E) -> E > 0 end, Queue).
960962
3> queue:to_list(Queue1).
961963
[1,2,3,4,5]
962964
```
@@ -998,7 +1000,7 @@ _Example:_
9981000

9991001
```erlang
10001002
1> Queue = queue:from_list([1,2,3,4,5,100]).
1001-
2> Queue1 = queue:delete_with(fun (E) -> E > 10, Queue).
1003+
2> Queue1 = queue:delete_with(fun (E) -> E > 10 end, Queue).
10021004
3> queue:to_list(Queue1).
10031005
[1,2,3,4,5]
10041006
```
@@ -1074,7 +1076,7 @@ delete_with_rear(_, []) ->
10741076
%%
10751077
%% An alternative would be to balance for equal list length when one side
10761078
%% is exhausted. Although this could be better for a general double
1077-
%% ended queue, it would more han double the amortized cost for
1079+
%% ended queue, it would more than double the amortized cost for
10781080
%% the normal case (one way queue).
10791081

10801082
%% Cons to head

0 commit comments

Comments
 (0)