-
splatnet3_scraper.query.QueryResponse.apply(func, key, partial=
True) Applies a function to the data.
Given a 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
keyargument of(0, "key1")will be treated asdata[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 thepartialargument isTrue, this method will apply the function to all keys in the data that match the given key or path. For example, if thekeyargument is(0, "key1")and thepartialargument isTrue, this will apply the function to all values within the JSON object where the path is...[0]["key1"]. If thepartialargument isFalse, 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 thepartialargument isTrue, the argument will be a representative of the value at the given key or path within 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
keyargument of(0, "key1")will be treated asdata[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 thepartialargument isTrue, this method will treat akeyargument of(0, "key1")as...[0]["key1"]rather than justdata[0]["key1"].- partial : bool¶
Whether the given key or path is a partial path. If
True, this method will treat akeyargument of(0, "key1")as...[0]["key1"]rather than justdata[0]["key1"]. IfFalse, this method will treat akeyargument of(0, "key1")asdata[0]["key1"]. Defaults toTrue.
- Returns:¶
T | list[T] – The result of applying the function to the data. If multiple paths match the given key or path, this will be a list of the results of applying the function to each path. If only a single path matches the given key or path, this will be the result of applying the function to that path.