Reap

WMA link


Reap[expr]

gives the result of evaluating expr, together with all values sown during this evaluation. Values sown with different tags are given in different lists.

Reap[expr, pattern]

only yields values sown with a tag matching pattern.
Reap[expr] is equivalent to Reap[expr, _].

Reap[expr, {$pattern_1$, $pattern_2$, ...}]

uses multiple patterns.

Reap[expr, pattern, f]

applies f on each tag and the corresponding values sown in the form f[tag, {$e_1$, $e_2$, ...}].

Find the unique elements of a list, keeping their order:

Sown values are reaped by the innermost matching Reap:

When no value is sown, an empty list is returned:

Range
Sow