Skip to content

Commit

Permalink
std.algorithm homonym docs need improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Dec 27, 2014
1 parent fa53835 commit 0701187
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions std/algorithm.d
Expand Up @@ -420,6 +420,9 @@ in many languages of functional flavor. The call $(D map!(fun)(range))
returns a range of which elements are obtained by applying $(D fun(a))
left to right for all elements $(D a) in $(D range). The original ranges are
not changed. Evaluation is done lazily.
See_Also:
$(WEB en.wikipedia.org/wiki/Map_(higher-order_function), Map (higher-order function))
*/
template map(fun...) if (fun.length >= 1)
{
Expand Down Expand Up @@ -1073,8 +1076,14 @@ result) is returned. The one-argument version $(D reduce!(fun)(range))
works similarly, but it uses the first element of the range as the
seed (the range must be non-empty).
See also: $(LREF sum) is similar to $(D reduce!((a, b) => a + b)) that offers
precise summing of floating point numbers.
Returns:
the accumulated $(D result)
See_Also:
$(WEB en.wikipedia.org/wiki/Fold_(higher-order_function), Fold (higher-order function))
$(LREF sum) is similar to $(D reduce!((a, b) => a + b)) that offers
precise summing of floating point numbers.
+/
template reduce(fun...) if (fun.length >= 1)
{
Expand Down Expand Up @@ -2017,16 +2026,24 @@ unittest
/**
$(D auto filter(Range)(Range rs) if (isInputRange!(Unqual!Range));)
Implements the homonym function present in various programming
languages of functional flavor. The call $(D filter!(predicate)(range))
returns a new range only containing elements $(D x) in $(D range) for
which $(D predicate(x)) is $(D true).
Implements the higher order filter function.
Params:
predicate = function to apply to each element of range
range = range of elements
Returns:
$(D filter!(predicate)(range)) returns a new range containing only elements $(D x) in $(D range) for
which $(D predicate(x)) returns $(D true).
See_Also:
$(WEB en.wikipedia.org/wiki/Filter_(higher-order_function), Filter (higher-order function))
*/
template filter(alias pred) if (is(typeof(unaryFun!pred)))
template filter(alias predicate) if (is(typeof(unaryFun!predicate)))
{
auto filter(Range)(Range rs) if (isInputRange!(Unqual!Range))
auto filter(Range)(Range range) if (isInputRange!(Unqual!Range))
{
return FilterResult!(unaryFun!pred, Range)(rs);
return FilterResult!(unaryFun!predicate, Range)(range);
}
}

Expand Down

0 comments on commit 0701187

Please sign in to comment.