Save the date! Google I/O returns May 18-20 Register now


Wraps a function to create a new scope for harvested values.

Used in the notebooks

Used in the tutorials

Harvested values live in one dynamic name scope (for a particular tag), and in strict mode, values with the same name cannot be collected or injected more than once. nest(f, scope=) will take all tagged values in f and put them into a nested dictionary with key . This enables having duplicate names in one namespace provided they are in different scopes. This is different from using a separate tag to namespace, as it enables creating nested/hierarchical structure within a single tag's namespace.


def foo(x):
  return sow(x, tag='test', name='x')
harvest(foo, tag='test')({}, 1.)  # (1., {'x': 1.})
harvest(nest(foo, scope='a'), tag='test')({}, 1.)  # (1., {'a': {'x': 1.} })

f a function to be transformed scope (str): a string that will act as the parent scope of all values tagged in f.

A semantically identical function to f, but when harvested, uses nested values according to the input scope.