splatnet3_scraper.query.QueryResponse.apply_reduce(func, reduce_func, key, partial=True)

Applies a function to the data and then reduces the result.

Given a function, a reduce function, and a key to apply the function to, this method will apply the function to the data at the given key. If the key is a tuple, this method will treat it as a path. For example, a key argument of (0, "key1") will be treated as data[0]["key1"]. If the key is a string, this method will treat it as a key in a dictionary. Integers will be treated as indices in a list. If the partial argument is True, this method will apply the function to all keys in the data that match the given key or path. For example, if the key argument is (0, "key1") and the partial argument is True, this will apply the function to all values within the JSON object where the path is ...[0]["key1"]. If the partial argument is False, this will only apply the function to the value at the absolute key or path in the data.

Parameters:
func : Callable[[Any], T]

The function to apply to the data. The function must take a single argument and return a value of type T. The argument that the function takes will be representative of the value at the given key or path. If the partial argument is True, the argument will be a representative of the value at the given key or path within the data.

reduce_func : Callable[[T], S]

The function to reduce the result of applying the function to the data. The function must take a single argument and return a value of type S. The argument that the function takes will be the result of applying the function to the data.

key : PathType | list[PathType]

The key or path to apply the function to. If the key is a tuple, this method will treat it as a path. For example, a key argument of (0, "key1") will be treated as data[0]["key1"]. If the key is a string, this method will treat it as a key in a dictionary. Integers will be treated as indices in a list. If the partial argument is True, this method will treat a key argument of (0, "key1") as ...[0]["key1"] rather than just data[0]["key1"].

partial : bool

Whether the given key or path is a partial path. If True, this method will treat a key argument of (0, "key1") as ...[0]["key1"] rather than just data[0]["key1"]. If False, this method will treat a key argument of (0, "key1") as data[0]["key1"]. Defaults to True.

Returns:

S – The result of applying the function to the data and then reducing the result. This will always be a single value of type S.