diff --git a/base/exports.jl b/base/exports.jl index d1fdd36231a16..8aff751aa0079 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -669,6 +669,7 @@ export complement, complement!, contains, + count, delete!, empty!, endof, diff --git a/base/reduce.jl b/base/reduce.jl index a479173df35e9..60a8a0467f184 100644 --- a/base/reduce.jl +++ b/base/reduce.jl @@ -151,6 +151,16 @@ min(f::Function, itr) = mapreduce(f, min, itr) sum(f::Function, itr) = mapreduce(f, + , itr) prod(f::Function, itr) = mapreduce(f, * , itr) +function count(pred::Function, itr) + s = 0 + for x in itr + if pred(x) + s+=1 + end + end + s +end + function any(pred::Function, itr) for x in itr if pred(x) diff --git a/doc/manual/complex-and-rational-numbers.rst b/doc/manual/complex-and-rational-numbers.rst index 6831ffe4efba8..79c15fb9aa05d 100644 --- a/doc/manual/complex-and-rational-numbers.rst +++ b/doc/manual/complex-and-rational-numbers.rst @@ -157,9 +157,7 @@ construct a complex value directly from its real and imaginary parts.:: julia> complex(a,b) 1 + 2im -This construction avoids the multiplication and addition operations, and also -sidesteps unexpected results that can arise with the former for certain values -of ``b``. +This construction avoids the multiplication and addition operations. ``Inf`` and ``NaN`` propagate through complex numbers in the real and imaginary parts of a complex number as described in the diff --git a/doc/stdlib/base.rst b/doc/stdlib/base.rst index 61a54cfd1d1df..f6b5b87ee3201 100644 --- a/doc/stdlib/base.rst +++ b/doc/stdlib/base.rst @@ -311,7 +311,8 @@ Iterable Collections .. function:: unique(itr) - Returns an array containing only the unique elements of the iterable ``itr``. + Returns an array containing only the unique elements of the iterable ``itr``, in +the order that the first of each set of equivalent elements originally appears. .. function:: reduce(op, v0, itr) @@ -345,6 +346,10 @@ Iterable Collections Returns the sum of all elements in a collection +.. function:: sum(f, itr) + + Sum the results of calling function ``f`` on each element of ``itr``. + .. function:: prod(itr) Returns the product of all elements of a collection @@ -357,11 +362,7 @@ Iterable Collections Test whether all elements of a boolean collection are true -.. function:: count(itr) -> Integer - - Count the number of boolean elements in ``itr`` which are true. - -.. function:: countp(p, itr) -> Integer +.. function:: count(p, itr) -> Integer Count the number of elements in ``itr`` for which predicate ``p`` is true.