oryx.core.harvest

Transforms a function into a "functionalized" version.

Sown values are namespaced using string "tags", where a value is sown (using sow) with a tag, and harvest will ignore any sown values that don't match its input tag. Harvest will take a function f :: X -> Y that has sown values and converts it into a function g :: Plants -> X -> (Y, Reaps).

The additional input to the function, called plants, are values that are injected into the function. plants is a dictionary mapping string names to values, and while f is being run, if a key in plants matches the name of a sown value, the value in plants is used instead of the sown value.

The additional output of the function, called reaps, are values that are collected from the function. reaps is a dictionary mapping string names to values, and while f is being run, if the name of a sown value is not in plants, it is added to the reaps dictionary and returned along with the original output of the function. A value can only be reaped if it is not also planted.

f a function to be transformed.
tag str, the harvest tag that will be reaped/planted.
allowlist an iterable of strings of names that will be planted/reaped where other names will be ignored.
blocklist an iterable of strings of names that will be ignored while planting/reaping.
mode str, either 'reap_plant' (the default) or 'plant_only'. In 'plant_only' mode, harvest will keep sows in the function that were not plant-ed.

A function that takes in an additional initial input (a dictionary mapping names to values to be injected) and an additional final output (a dictionary mapping names to values that were collected).