diff --git a/src/caoscrawler/sync_graph.py b/src/caoscrawler/sync_graph.py index 36ed36d7864059fc8f169000313186af9f1eb4b0..dc97f2c338f3cb354171b6ac65d9106d47b93a5e 100644 --- a/src/caoscrawler/sync_graph.py +++ b/src/caoscrawler/sync_graph.py @@ -44,16 +44,24 @@ logger = logging.getLogger(__name__) def _for_each_scalar_value(node: SyncNode, condition: Callable[[Any], bool], kind: str, - value: Any = None): + value: Callable[[Any], Any] = None): """ helper function that performs an action on each value element of each property of a node - The action (remove or set) is performed on each property value of each property: in case on + The argument "kind" determines which action is performed on each property value: + The action (remove or set) is performed on each property value of each property: in case of lists, it is performed on each list element. The action is only performed if the condition that is provided is fulfilled, i.e. the callable ``condition`` returns True. The callable ``condition`` must take the property value (or list element) as the sole argument. Thus, with "remove" you can conditionally remove values and with "set" you can conditionally - replace values + replace values. + + Args: + node (SyncNode): The node which provides the properties (and their values) to operate on. + condition (Callable): A function with one argument which is interpreted as a condition: Only if + it returns True for the property value, the action is executed. + kind (str): Either "remove" or "set" depending on whether you want to remove the property or replace the property. + value (Callable): A function returning a new value that is set as the property value. This function receives the old value as the single argument. """ for p in node.properties: if isinstance(p.value, list):