Skip to content

Commit

Permalink
add a note on when to use foreach instead of map
Browse files Browse the repository at this point in the history
NEWS for `foreach`

[ci skip]
  • Loading branch information
JeffBezanson committed Oct 26, 2015
1 parent da6e1f3 commit 71fc3b3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ Library improvements
appropriate. The `sparsevec` function returns a one-dimensional sparse
vector instead of a one-column sparse matrix. ([#13440])

* New `foreach` function for calling a function on every element of a collection when
the results are not needed.

Deprecated or removed
---------------------

Expand Down
2 changes: 2 additions & 0 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,8 @@ doc"""
Call function `f` on each element of iterable `c`.
For multiple iterable arguments, `f` is called elementwise.
`foreach` should be used instead of `map` when the results of `f` are not
needed, for example in `foreach(println, array)`.
"""
foreach(f) = (f(); nothing)
foreach(f, itr) = (for x in itr; f(x); end; nothing)
Expand Down

0 comments on commit 71fc3b3

Please sign in to comment.