Skip to content

Commit

Permalink
add back count(pred,itr). closes #3180
Browse files Browse the repository at this point in the history
some doc updates
  • Loading branch information
JeffBezanson committed May 23, 2013
1 parent b1b839c commit 9bf4437
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ export
complement,
complement!,
contains,
count,
delete!,
empty!,
endof,
Expand Down
10 changes: 10 additions & 0 deletions base/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions doc/manual/complex-and-rational-numbers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions doc/stdlib/base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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.

Expand Down

0 comments on commit 9bf4437

Please sign in to comment.