Function

Creating Function

Syntax shortcut to create sequential and concurrent functions

theflow supports >> operator to create a sequential function, and supports a // operator to create concurrent function.

When running func1 >> func2, it will create a sequential function that runs func1 first, then func2.

When running func1 // func2, it will create a concurrent function that runs func1 and func2 at the same time and returns a tuple of results.

Function internals

Declare and list protected keywords

Some names are not allowed as node or param names, because they might conflict with important attributes and methods of Function, like config, set

When you create your own Function, if you want to avoid any naming conflict with the subclass, you can reserve the names in _keywords. This will raise error when future subclasses use one or more of those keywords as node and param names.

You can list a Function’s keywords with cls._protected_keywords(). This will return a dictionary of {keyword-name: class-that-defines-that-keyword}. It will traverse mro and look for _keywords, so don’t worry about the child class _keywords replacing parent class _keywords.

class A(Function):
    _keywords = ["x", "y"]

class B(A):
    _keywords = ["m"]

B._protected_keywords()   # {"x": A, "y": A, "m": B}