Skip to content

Commit

Permalink
Note possible reuse of return values of map function for mapreduce
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
simonster committed Mar 17, 2015
1 parent ff3723d commit 9e777b0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions doc/stdlib/collections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -464,16 +464,18 @@ Iterable Collections
:func:`mapreduce` is functionally equivalent to calling ``reduce(op,
v0, map(f, itr))``, but will in general execute faster since no
intermediate collection needs to be created. See documentation for
:func:`reduce` and ``map``.
:func:`reduce` and :func:`map`.

.. doctest::

julia> mapreduce(x->x^2, +, [1:3]) # == 1 + 4 + 9
14

The associativity of the reduction is implementation-dependent. Use
:func:`mapfoldl` or :func:`mapfoldr` instead for guaranteed left or
right associativity.
The associativity of the reduction is implementation-dependent.
Additionally, some implementations may reuse the return value of
``f`` for elements that appear multiple times in ``itr``.
Use :func:`mapfoldl` or :func:`mapfoldr` instead for guaranteed
left or right associativity and invocation of ``f`` for every value.

.. function:: mapreduce(f, op, itr)

Expand Down

0 comments on commit 9e777b0

Please sign in to comment.