added docs to the exported functions
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
from manipulator.query import treat_query
|
||||
|
||||
def get(data, query):
|
||||
"""traverses data based on the query.
|
||||
|
||||
- params:
|
||||
- data: the input to traverse
|
||||
- query: the rules for traversal
|
||||
- complexity: determined by the complexity of the query
|
||||
- returns: the data found at the leaves of the traversal"""
|
||||
selectors = treat_query(query)
|
||||
|
||||
for selector in selectors:
|
||||
|
@@ -3,6 +3,15 @@ import copy
|
||||
from manipulator.query import treat_query
|
||||
|
||||
def update(inpt, query, fn, in_place=True):
|
||||
"""transforms data based on the query dynamically.
|
||||
|
||||
- params:
|
||||
- data: the input to transform
|
||||
- query: the rules for traversal
|
||||
- fn: a transformation function for the leaves
|
||||
- in_place: determines whether we should perform the transformations in place (True per default)
|
||||
- complexity: determined by the complexity of the query
|
||||
- returns: the transformed data"""
|
||||
if in_place:
|
||||
data = inpt
|
||||
else:
|
||||
@@ -31,4 +40,13 @@ def update(inpt, query, fn, in_place=True):
|
||||
|
||||
|
||||
def set(inpt, query, val, in_place=True):
|
||||
"""transforms data based on the query statically.
|
||||
|
||||
- params:
|
||||
- data: the input to transform
|
||||
- query: the rules for traversal
|
||||
- val: the value to which the leaves should be set
|
||||
- in_place: determines whether we should perform the transformations in place (True per default)
|
||||
- complexity: determined by the complexity of the query
|
||||
- returns: the transformed data"""
|
||||
return update(inpt, query, lambda _: val, in_place)
|
||||
|
Reference in New Issue
Block a user