Skip to content

Sow ​

Sends a value to the nearest enclosing Reap, and returns it.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageSow✓
Sow(e)Records ee (evaluated) into the nearest enclosing Reap's untagged group, and returns ee.
Sow(e, tag)Like Sow(e)Sow(e), but records under tagtag instead of the untagged group.
Typed signatures
TypePackageApplies
(any, any?) -> anycombinatoricsalways

Domain: Collections

Details
  • A SowSow with no enclosing ReapReap is a no-op — it still returns ee, nothing is recorded anywhere.
  • A SowSow inside a NESTED ReapReap feeds only the innermost one; it does not also reach further out, matching Wolfram (an inner ReapReap "consumes" what's sown inside it).

Examples

Basic #

Sow feeds the nearest Reap

live ↗
InReap(Sow(5))\mathrm{Reap}(\mathrm{Sow}(5))Out[5,[[5]]]\bigl\lbrack5, \bigl\lbrack\bigl\lbrack5\bigr\rbrack\bigr\rbrack\bigr\rbrack

Sow outside any Reap is a no-op that still returns its value

live ↗
InSow(7)\mathrm{Sow}(7)Out77
live ↗
InReap(∑k=10(Sow(k2)+1))\mathrm{Reap}(\sum_{k=10}(\mathrm{Sow}(k^2)+1))Out[395,[[1,4,9,16,25,36,49,64,81,100]]]\bigl\lbrack395, \bigl\lbrack\bigl\lbrack1, 4, 9, 16, 25, 36, 49, 64, 81, 100\bigr\rbrack\bigr\rbrack\bigr\rbrack
Applications #
live ↗
InReap(Do(Sow(k,k2 mod 10),[k,20]))\mathrm{Reap}(\mathrm{Do}(\mathrm{Sow}(k, k^2\bmod10), \bigl\lbrack k, 20\bigr\rbrack))Out[Null,[[1,9,11,19],[2,8,12,18],[3,7,13,17],[4,6,14,16],[5,15],[10,20]]]\bigl\lbrack\mathrm{Null}, \bigl\lbrack\bigl\lbrack1, 9, 11, 19\bigr\rbrack, \bigl\lbrack2, 8, 12, 18\bigr\rbrack, \bigl\lbrack3, 7, 13, 17\bigr\rbrack, \bigl\lbrack4, 6, 14, 16\bigr\rbrack, \bigl\lbrack5, 15\bigr\rbrack, \bigl\lbrack10, 20\bigr\rbrack\bigr\rbrack\bigr\rbrack
Properties #

Outside a collector, Sow simply returns its argument

live ↗
InSow(x)\mathrm{Sow}(x)Outxx
About
Examples5
Checked againstWolfram Language 5 agree
CrosswalkWolfram Language

See also: Reap