Reap
[expr]Reap
[expr, pattern]Reap[expr]
is equivalent to Reap[expr, _]
.Reap
[expr, {$pattern_1$, $pattern_2$, ...}]Reap
[expr, pattern, f]f[tag, {$e_1$, $e_2$, ...}]
.Reap[Sow[3]; Sow[1]]
Reap[Sow[2, {x, x, x}]; Sow[3, x]; Sow[4, y]; Sow[4, 1], {_Symbol, _Integer, x}, f]
Find the unique elements of a list, keeping their order:
Reap[Sow[Null, {a, a, b, d, c, a}], _, # &][[2]]
Sown values are reaped by the innermost matching Reap
:
Reap[Reap[Sow[a, x]; Sow[b, 1], _Symbol, Print["Inner: ", #1]&];, _, f]
When no value is sown, an empty list is returned:
Reap[x]