added docs to the exported functions

This commit is contained in:
hellerve
2017-01-17 14:59:06 +01:00
parent 1762e29a0c
commit 29c91b2570
2 changed files with 25 additions and 0 deletions

View File

@@ -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:

View File

@@ -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)