Skip to content

Commit 09d97ad

Browse files
authored
Merge pull request #4985 from wilzbach/other-languages
Provide references to other common names
2 parents ca80132 + 8d5b051 commit 09d97ad

File tree

8 files changed

+68
-19
lines changed

8 files changed

+68
-19
lines changed

std/algorithm/iteration.d

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,9 @@ Returns: A range of elements of type $(D Tuple!(ElementType!R, uint)),
13841384
representing each consecutively unique element and its respective number of
13851385
occurrences in that run. This will be an input range if $(D R) is an input
13861386
range, and a forward range in all other cases.
1387+
1388+
See_Also: $(LREF chunkBy), which chunks an input range into subranges
1389+
of equivalent adjacent elements.
13871390
*/
13881391
Group!(pred, Range) group(alias pred = "a == b", Range)(Range r)
13891392
{
@@ -1820,6 +1823,8 @@ private struct ChunkByImpl(alias pred, Range)
18201823

18211824
/**
18221825
* Chunks an input range into subranges of equivalent adjacent elements.
1826+
* In other languages this is often called `partitionBy`, `groupBy`
1827+
* or `sliceWhen`.
18231828
*
18241829
* Equivalence is defined by the predicate $(D pred), which can be either
18251830
* binary, which is passed to $(REF binaryFun, std,functional), or unary, which is
@@ -2061,7 +2066,7 @@ version(none) // This requires support for non-equivalence relations
20612066
/**
20622067
Lazily joins a range of ranges with a separator. The separator itself
20632068
is a range. If a separator is not provided, then the ranges are
2064-
joined directly without anything in between them (often called $(D flatten)
2069+
joined directly without anything in between them (often called `flatten`
20652070
in other languages).
20662071
20672072
Params:

std/algorithm/mutation.d

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,12 +2080,11 @@ if (isBidirectionalRange!Range
20802080
/**
20812081
Reverses $(D r) in-place. Performs $(D r.length / 2) evaluations of $(D
20822082
swap).
2083-
20842083
Params:
20852084
r = a bidirectional range with swappable elements or a random access range with a length member
20862085
20872086
See_Also:
2088-
$(HTTP sgi.com/tech/stl/_reverse.html, STL's _reverse)
2087+
$(HTTP sgi.com/tech/stl/_reverse.html, STL's _reverse), $(REF retro, std,range) for a lazy reversed range view
20892088
*/
20902089
void reverse(Range)(Range r)
20912090
if (isBidirectionalRange!Range && !isRandomAccessRange!Range

std/algorithm/searching.d

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ are true.
158158
Checks if $(I _any) of the elements verifies $(D pred).
159159
$(D !any) can be used to verify that $(I none) of the elements verify
160160
$(D pred).
161+
This is sometimes called `exists` in other languages.
161162
+/
162163
template any(alias pred = "a")
163164
{
@@ -740,6 +741,8 @@ size_t count(alias pred = "true", R)(R haystack)
740741
$(D startsWith!pred(haystack, needles)) is $(D true). If
741742
$(D startsWith!pred(haystack, needles)) is not $(D true) for any element in
742743
$(D haystack), then $(D -1) is returned.
744+
745+
See_Also: $(REF indexOf, std,string)
743746
+/
744747
ptrdiff_t countUntil(alias pred = "a == b", R, Rs...)(R haystack, Rs needles)
745748
if (isForwardRange!R
@@ -1666,6 +1669,8 @@ pred).
16661669
To _find the last element of a bidirectional $(D haystack) satisfying
16671670
$(D pred), call $(D find!(pred)(retro(haystack))). See $(REF retro, std,range).
16681671
1672+
`find` behaves similar to `dropWhile` in other languages.
1673+
16691674
Params:
16701675
16711676
pred = The predicate for determining if a given element is the one being
@@ -3262,6 +3267,7 @@ unittest
32623267
/**
32633268
Iterates the passed range and returns the minimal element.
32643269
A custom mapping function can be passed to `map`.
3270+
In other languages this is sometimes called `argmin`.
32653271
32663272
Complexity: O(n)
32673273
Exactly `n - 1` comparisons are needed.
@@ -3353,6 +3359,7 @@ auto minElement(alias map = "a", Range, RangeElementType = ElementType!Range)
33533359
/**
33543360
Iterates the passed range and returns the maximal element.
33553361
A custom mapping function can be passed to `map`.
3362+
In other languages this is sometimes called `argmax`.
33563363
33573364
Complexity:
33583365
Exactly `n - 1` comparisons are needed.
@@ -4260,10 +4267,11 @@ private void skipAll(alias pred = "a == b", R, Es...)(ref R r, Es es)
42604267
}
42614268

42624269
/**
4263-
Interval option specifier for $(D until) (below) and others.
4270+
Interval option specifier for `until` (below) and others.
42644271
42654272
If set to $(D OpenRight.yes), then the interval is open to the right
42664273
(last element is not included).
4274+
This is similar to `takeWhile` in other languages.
42674275
42684276
Otherwise if set to $(D OpenRight.no), then the interval is closed to the right
42694277
(last element included).
@@ -4410,8 +4418,8 @@ struct Until(alias pred, Range, Sentinel) if (isInputRange!Range)
44104418
import std.algorithm.comparison : equal;
44114419
import std.typecons : No;
44124420
int[] a = [ 1, 2, 4, 7, 7, 2, 4, 7, 3, 5];
4413-
assert(equal(a.until(7), [1, 2, 4][]));
4414-
assert(equal(a.until(7, No.openRight), [1, 2, 4, 7][]));
4421+
assert(equal(a.until(7), [1, 2, 4]));
4422+
assert(equal(a.until(7, No.openRight), [1, 2, 4, 7]));
44154423
}
44164424

44174425
@safe unittest
@@ -4423,10 +4431,10 @@ struct Until(alias pred, Range, Sentinel) if (isInputRange!Range)
44234431
static assert(isForwardRange!(typeof(a.until(7))));
44244432
static assert(isForwardRange!(typeof(until!"a == 2"(a, No.openRight))));
44254433

4426-
assert(equal(a.until(7), [1, 2, 4][]));
4427-
assert(equal(a.until([7, 2]), [1, 2, 4, 7][]));
4428-
assert(equal(a.until(7, No.openRight), [1, 2, 4, 7][]));
4429-
assert(equal(until!"a == 2"(a, No.openRight), [1, 2][]));
4434+
assert(equal(a.until(7), [1, 2, 4]));
4435+
assert(equal(a.until([7, 2]), [1, 2, 4, 7]));
4436+
assert(equal(a.until(7, No.openRight), [1, 2, 4, 7]));
4437+
assert(equal(until!"a == 2"(a, No.openRight), [1, 2]));
44304438
}
44314439

44324440
unittest // bugzilla 13171

std/array.d

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,13 +342,15 @@ Returns:
342342

343343
/**
344344
Returns a newly allocated associative _array from a range of key/value tuples.
345+
345346
Params: r = An input range of tuples of keys and values.
346347
Returns: A newly allocated associative array out of elements of the input
347348
range, which must be a range of tuples (Key, Value). Returns a null associative
348349
array reference when given an empty range.
349350
Duplicates: Associative arrays have unique keys. If r contains duplicate keys,
350351
then the result will contain the value of the last pair for that key in r.
351-
See_Also: $(REF Tuple, std,typecons)
352+
353+
See_Also: $(REF Tuple, std,typecons), $(REF zip, std,range)
352354
*/
353355

354356
auto assocArray(Range)(Range r)
@@ -374,7 +376,7 @@ auto assocArray(Range)(Range r)
374376
{
375377
import std.range;
376378
import std.typecons;
377-
auto a = assocArray(zip([0, 1, 2], ["a", "b", "c"]));
379+
auto a = assocArray(zip([0, 1, 2], ["a", "b", "c"])); // aka zipMap
378380
assert(is(typeof(a) == string[int]));
379381
assert(a == [0:"a", 1:"b", 2:"c"]);
380382

std/functional.d

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,8 @@ template adjoin(F...) if (F.length > 1)
883883
function $(D f(x)) that in turn returns $(D
884884
fun[0](fun[1](...(x)))...). Each function can be a regular
885885
functions, a delegate, or a string.
886+
887+
See_Also: $(LREF pipe)
886888
*/
887889
template compose(fun...)
888890
{
@@ -936,6 +938,8 @@ template compose(fun...)
936938
// integer
937939
int[] a = pipe!(readText, split, map!(to!(int)))("file.txt");
938940
----
941+
942+
See_Also: $(LREF compose)
939943
*/
940944
alias pipe(fun...) = compose!(Reverse!(fun));
941945

std/range/package.d

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ Returns:
205205
A bidirectional range with length if `r` also provides a length. Or,
206206
if `r` is a random access range, then the return value will be random
207207
access as well.
208+
See_Also:
209+
$(REF reverse, std,algorithm,mutation) for mutating the source range directly.
208210
*/
209211
auto retro(Range)(Range r)
210212
if (isBidirectionalRange!(Unqual!Range))
@@ -837,6 +839,8 @@ Returns:
837839
An input range at minimum. If all of the ranges in `rs` provide
838840
a range primitive, the returned range will also provide that range
839841
primitive.
842+
843+
See_Also: $(LREF only) to chain values to a range
840844
*/
841845
auto chain(Ranges...)(Ranges rs)
842846
if (Ranges.length > 0 &&
@@ -2872,17 +2876,27 @@ pure @safe nothrow @nogc unittest
28722876

28732877
/++
28742878
Convenience function which calls
2875-
$(D range.$(LREF popFrontN)(n)) and returns $(D range). $(D drop)
2876-
makes it easier to pop elements from a range
2879+
`range.$(REF popFrontN, std, range, primitives)(n)) and returns `range`.
2880+
`drop` makes it easier to pop elements from a range
28772881
and then pass it to another function within a single expression,
2878-
whereas $(D popFrontN) would require multiple statements.
2882+
whereas `popFrontN` would require multiple statements.
2883+
2884+
`dropBack` provides the same functionality but instead calls
2885+
`range.$(REF popBackN, std, range, primitives)(n))
28792886
2880-
$(D dropBack) provides the same functionality but instead calls
2881-
$(D range.popBackN(n)).
2887+
Note: `drop` and `dropBack` will only pop $(I up to)
2888+
`n` elements but will stop if the range is empty first.
2889+
In other languages this is sometimes called `skip`.
28822890
2883-
Note: $(D drop) and $(D dropBack) will only pop $(I up to)
2884-
$(D n) elements but will stop if the range is empty first.
2891+
Params:
2892+
range = the input range to drop from
2893+
n = the number of elements to drop
2894+
2895+
Returns:
2896+
`range` with up to `n` elements dropped
28852897
2898+
See_Also:
2899+
$(REF popFront, std, range, primitives),$(REF popBackN, std, range, primitives)
28862900
+/
28872901
R drop(R)(R range, size_t n)
28882902
if (isInputRange!R)
@@ -2969,6 +2983,10 @@ R dropBack(R)(R range, size_t n)
29692983
29702984
Returns:
29712985
`range` with `n` elements dropped
2986+
2987+
See_Also:
2988+
$(REF popFrontExcatly, std, range, primitives),
2989+
$(REF popBackExcatly, std, range, primitives)
29722990
+/
29732991
R dropExactly(R)(R range, size_t n)
29742992
if (isInputRange!R)
@@ -7497,6 +7515,14 @@ having to perform dynamic memory allocation.
74977515
As copying the range means copying all elements, it can be
74987516
safely returned from functions. For the same reason, copying
74997517
the returned range may be expensive for a large number of arguments.
7518+
7519+
Params:
7520+
values = the values to assemble together
7521+
7522+
Returns:
7523+
A `RandomAccessRange` of the assembled values.
7524+
7525+
See_Also: $(LREF chain) to chain ranges
75007526
*/
75017527
auto only(Values...)(auto ref Values values)
75027528
if (!is(CommonType!Values == void) || Values.length == 0)

std/range/primitives.d

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,8 @@ auto walkLength(Range)(Range range, const size_t upTo)
16761676
16771677
$(D popBackN) will behave the same but instead removes elements from
16781678
the back of the (bidirectional) range instead of the front.
1679+
1680+
See_Also: $(REF drop, std, range), $(REF dropBack, std, range)
16791681
*/
16801682
size_t popFrontN(Range)(ref Range r, size_t n)
16811683
if (isInputRange!Range)
@@ -1807,6 +1809,8 @@ size_t popBackN(Range)(ref Range r, size_t n)
18071809
18081810
$(D popBackExactly) will behave the same but instead removes elements from
18091811
the back of the (bidirectional) range instead of the front.
1812+
1813+
See_Also: $(REF dropExcatly, std, range), $(REF dropBackExactly, std, range)
18101814
*/
18111815
void popFrontExactly(Range)(ref Range r, size_t n)
18121816
if (isInputRange!Range)

std/string.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ alias CaseSensitive = Flag!"caseSensitive";
369369
If the sequence starting at $(D startIdx) does not represent a well
370370
formed codepoint, then a $(REF UTFException, std,utf) may be thrown.
371371
372+
See_Also: $(REF countUntil, std,algorithm,searching)
372373
+/
373374
ptrdiff_t indexOf(Range)(Range s, in dchar c,
374375
in CaseSensitive cs = Yes.caseSensitive)

0 commit comments

Comments
 (0)