mirror of
https://github.com/dlang/phobos.git
synced 2025-05-10 22:18:03 +03:00
Replace 'reduce' with 'fold' in the documentation
This commit is contained in:
parent
b72d5055a0
commit
9cc2a5ae59
2 changed files with 19 additions and 12 deletions
|
@ -40,11 +40,12 @@ $(T2 map,
|
||||||
$(T2 permutations,
|
$(T2 permutations,
|
||||||
Lazily computes all permutations using Heap's algorithm.)
|
Lazily computes all permutations using Heap's algorithm.)
|
||||||
$(T2 reduce,
|
$(T2 reduce,
|
||||||
$(D reduce!((a, b) => a + b)([1, 2, 3, 4])) returns $(D 10).)
|
$(D reduce!((a, b) => a + b)([1, 2, 3, 4])) returns $(D 10).
|
||||||
|
This is the old implementation of `fold`.)
|
||||||
$(T2 splitter,
|
$(T2 splitter,
|
||||||
Lazily splits a range by a separator.)
|
Lazily splits a range by a separator.)
|
||||||
$(T2 sum,
|
$(T2 sum,
|
||||||
Same as $(D reduce), but specialized for accurate summation.)
|
Same as $(D fold), but specialized for accurate summation.)
|
||||||
$(T2 uniq,
|
$(T2 uniq,
|
||||||
Iterates over the unique elements in a range, which is assumed sorted.)
|
Iterates over the unique elements in a range, which is assumed sorted.)
|
||||||
)
|
)
|
||||||
|
@ -2447,11 +2448,13 @@ unittest
|
||||||
/++
|
/++
|
||||||
Implements the homonym function (also known as $(D accumulate), $(D
|
Implements the homonym function (also known as $(D accumulate), $(D
|
||||||
compress), $(D inject), or $(D foldl)) present in various programming
|
compress), $(D inject), or $(D foldl)) present in various programming
|
||||||
languages of functional flavor. The call $(D reduce!(fun)(seed,
|
languages of functional flavor. There is also $(LREF fold) which does
|
||||||
range)) first assigns $(D seed) to an internal variable $(D result),
|
the same thing but with the opposite parameter order.
|
||||||
also called the accumulator. Then, for each element $(D x) in $(D
|
The call $(D reduce!(fun)(seed, range)) first assigns $(D seed) to
|
||||||
range), $(D result = fun(result, x)) gets evaluated. Finally, $(D
|
an internal variable $(D result), also called the accumulator.
|
||||||
result) is returned. The one-argument version $(D reduce!(fun)(range))
|
Then, for each element $(D x) in $(D range), $(D result = fun(result, x))
|
||||||
|
gets evaluated. Finally, $(D result) is returned.
|
||||||
|
The one-argument version $(D reduce!(fun)(range))
|
||||||
works similarly, but it uses the first element of the range as the
|
works similarly, but it uses the first element of the range as the
|
||||||
seed (the range must be non-empty).
|
seed (the range must be non-empty).
|
||||||
|
|
||||||
|
@ -2461,6 +2464,10 @@ Returns:
|
||||||
See_Also:
|
See_Also:
|
||||||
$(WEB en.wikipedia.org/wiki/Fold_(higher-order_function), Fold (higher-order function))
|
$(WEB en.wikipedia.org/wiki/Fold_(higher-order_function), Fold (higher-order function))
|
||||||
|
|
||||||
|
$(LREF fold) is functionally equivalent to $(LREF reduce) with the argument order reversed,
|
||||||
|
and without the need to use $(LREF tuple) for multiple seeds. This makes it easier
|
||||||
|
to use in UFCS chains.
|
||||||
|
|
||||||
$(LREF sum) is similar to $(D reduce!((a, b) => a + b)) that offers
|
$(LREF sum) is similar to $(D reduce!((a, b) => a + b)) that offers
|
||||||
precise summing of floating point numbers.
|
precise summing of floating point numbers.
|
||||||
+/
|
+/
|
||||||
|
@ -3956,8 +3963,8 @@ if (isSomeChar!C)
|
||||||
/**
|
/**
|
||||||
Sums elements of $(D r), which must be a finite
|
Sums elements of $(D r), which must be a finite
|
||||||
$(XREF_PACK_NAMED range,primitives,isInputRange,input range). Although
|
$(XREF_PACK_NAMED range,primitives,isInputRange,input range). Although
|
||||||
conceptually $(D sum(r)) is equivalent to $(LREF reduce)!((a, b) => a +
|
conceptually $(D sum(r)) is equivalent to $(LREF fold)!((a, b) => a +
|
||||||
b)(0, r), $(D sum) uses specialized algorithms to maximize accuracy,
|
b)(r, 0), $(D sum) uses specialized algorithms to maximize accuracy,
|
||||||
as follows.
|
as follows.
|
||||||
|
|
||||||
$(UL
|
$(UL
|
||||||
|
@ -3977,7 +3984,7 @@ $(LI In all other cases, a simple element by element addition is done.)
|
||||||
For floating point inputs, calculations are made in
|
For floating point inputs, calculations are made in
|
||||||
$(DDLINK spec/type, Types, $(D real))
|
$(DDLINK spec/type, Types, $(D real))
|
||||||
precision for $(D real) inputs and in $(D double) precision otherwise
|
precision for $(D real) inputs and in $(D double) precision otherwise
|
||||||
(Note this is a special case that deviates from $(D reduce)'s behavior,
|
(Note this is a special case that deviates from $(D fold)'s behavior,
|
||||||
which would have kept $(D float) precision for a $(D float) range).
|
which would have kept $(D float) precision for a $(D float) range).
|
||||||
For all other types, the calculations are done in the same type obtained
|
For all other types, the calculations are done in the same type obtained
|
||||||
from from adding two elements of the range, which may be a different
|
from from adding two elements of the range, which may be a different
|
||||||
|
@ -3990,7 +3997,7 @@ and precision used for summation.
|
||||||
|
|
||||||
Note that these specialized summing algorithms execute more primitive operations
|
Note that these specialized summing algorithms execute more primitive operations
|
||||||
than vanilla summation. Therefore, if in certain cases maximum speed is required
|
than vanilla summation. Therefore, if in certain cases maximum speed is required
|
||||||
at expense of precision, one can use $(D reduce!((a, b) => a + b)(0, r)), which
|
at expense of precision, one can use $(D fold!((a, b) => a + b)(r, 0)), which
|
||||||
is not specialized for summation.
|
is not specialized for summation.
|
||||||
|
|
||||||
Params:
|
Params:
|
||||||
|
|
|
@ -9045,7 +9045,7 @@ struct NullSink
|
||||||
in the case of the version of $(D tee) that takes a function, the function
|
in the case of the version of $(D tee) that takes a function, the function
|
||||||
will not actually be executed until the range is "walked" using functions
|
will not actually be executed until the range is "walked" using functions
|
||||||
that evaluate ranges, such as $(XREF array,array) or
|
that evaluate ranges, such as $(XREF array,array) or
|
||||||
$(XREF_PACK algorithm,iteration,reduce).
|
$(XREF_PACK algorithm,iteration,fold).
|
||||||
|
|
||||||
Params:
|
Params:
|
||||||
pipeOnPop = If `Yes.pipeOnPop`, simply iterating the range without ever
|
pipeOnPop = If `Yes.pipeOnPop`, simply iterating the range without ever
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue