WOLFRAM

Reap[expr]

gives the value of expr together with all expressions to which Sow has been applied during its evaluation. Expressions sown using Sow[e] or Sow[e,tagi] with different tags are given in different lists.

Reap[expr,patt]

reaps only expressions sown with tags that match patt.

Reap[expr,{patt1,patt2,}]

puts expressions associated with each of the patti in a separate list.

Reap[expr,patt,f]

returns {expr,{f[tag1,{e11,e12,}],}}.

Details

  • Sow and Reap provide a convenient way to accumulate a list of intermediate results in a computation.
  • Reap accumulates expressions in the order in which Sow is applied to them.
  • Expressions sown with a particular tag are collected by the innermost Reap whose pattern matches the tag.
  • Reap[expr] is equivalent to Reap[expr,_].
  • Reap has attribute HoldFirst.

Examples

open allclose all

Basic Examples  (2)Summary of the most common use cases

Evaluate a sequence of expressions, "reaping" ones that have been "sown":

Out[1]=1

Compute a sum, "reaping" i^2 "sown" at each step:

Out[1]=1

Scope  (2)Survey of the scope of standard use cases

Make a separate sublist for each tag being reaped:

Out[1]=1

Count the number of instances of each integer separating the negative:

Out[1]=1

Generalizations & Extensions  (1)Generalized and extended use cases

Apply f to each distinct tag and list of values:

Out[1]=1
Out[2]=2

Applications  (2)Sample problems that can be solved with this function

Find the list of values sampled by Plot:

Remove duplicates from a list, keeping original order:

Out[2]=2

This is like Union without the sorting:

Out[3]=3

Properties & Relations  (3)Properties of the function, and connections to other functions

If no expressions are sown, Reap returns an empty list of expressions it has reaped:

Out[1]=1

Reap collects expressions in exactly the order they are sown:

Out[1]=1

The list associated with the first tag to be encountered is given first:

Out[1]=1
Out[2]=2
Wolfram Research (2003), Reap, Wolfram Language function, https://reference.wolfram.com/language/ref/Reap.html.
Wolfram Research (2003), Reap, Wolfram Language function, https://reference.wolfram.com/language/ref/Reap.html.

Text

Wolfram Research (2003), Reap, Wolfram Language function, https://reference.wolfram.com/language/ref/Reap.html.

Wolfram Research (2003), Reap, Wolfram Language function, https://reference.wolfram.com/language/ref/Reap.html.

CMS

Wolfram Language. 2003. "Reap." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Reap.html.

Wolfram Language. 2003. "Reap." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Reap.html.

APA

Wolfram Language. (2003). Reap. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Reap.html

Wolfram Language. (2003). Reap. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Reap.html

BibTeX

@misc{reference.wolfram_2025_reap, author="Wolfram Research", title="{Reap}", year="2003", howpublished="\url{https://reference.wolfram.com/language/ref/Reap.html}", note=[Accessed: 31-March-2025 ]}

@misc{reference.wolfram_2025_reap, author="Wolfram Research", title="{Reap}", year="2003", howpublished="\url{https://reference.wolfram.com/language/ref/Reap.html}", note=[Accessed: 31-March-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_reap, organization={Wolfram Research}, title={Reap}, year={2003}, url={https://reference.wolfram.com/language/ref/Reap.html}, note=[Accessed: 31-March-2025 ]}

@online{reference.wolfram_2025_reap, organization={Wolfram Research}, title={Reap}, year={2003}, url={https://reference.wolfram.com/language/ref/Reap.html}, note=[Accessed: 31-March-2025 ]}