Skip to content

Scan

Status: Stable

documented, exercised by the test suite and/or worked examples, with no known limitations recorded.

Description

Scan[f, expr]

Applies f to each element of expr for its side effects and returns Null, discarding the results.

Scan[f, expr, levelspec]

Applies f to the parts of expr selected by levelspec (default {1}), depth-first with leaves before roots. Option Heads->True also visits heads. Throw exits to an enclosing Catch; Return[ret] makes the final value ret. Over an association, applies f to each value.

Examples (4)

Every input below was run against the current Mathilda build and its output recorded.

Basic examples (3)

In[1]:= s = 0; Scan[(s = s + #) &, <|"a" -> 1, "b" -> 2, "c" -> 3|>]; s
Out[1]= 6

In[2]:= Scan[Print, {{{a}}}, Infinity] a {a} {{a}}
Out[2]= {{Null a^3}}

In[3]:= Catch[Scan[If[# > 5, Throw[#]] &, {2, 4, 6, 8}]]
Out[3]= 6

Options (1)

In[4]:= Scan[Print, {a, b}, Heads -> True] List a b
Out[4]= List Null a b

Implementation notes

Attributes: Protected.

References

See also: Map, Throw, Catch, NDArray