Doc string and method name

This commit is contained in:
Bertrand Benjamin 2018-01-21 12:14:16 +03:00
parent 0f3e0870fe
commit 273675b243
1 changed files with 10 additions and 10 deletions

View File

@ -182,7 +182,7 @@ class Tree(object):
return cls(node, l_value, r_value)
def map_leaf(self, function):
def map_on_leaf(self, function):
""" Map on leafs a function
:param function: take leaf value returns other value
@ -200,7 +200,7 @@ class Tree(object):
| > 3
| > 4
> 2
>>> print(t.map_leaf(lambda x:2*x))
>>> print(t.map_on_leaf(lambda x:2*x))
+
> *
| > 6
@ -209,19 +209,19 @@ class Tree(object):
"""
try:
left_applied = self.left_value.map_leaf(function)
left_applied = self.left_value.map_on_leaf(function)
except AttributeError:
left_applied = function(self.left_value)
try:
right_applied = self.right_value.map_leaf(function)
right_applied = self.right_value.map_on_leaf(function)
except AttributeError:
right_applied = function(self.right_value)
return Tree(self.node, left_applied, right_applied)
def apply_on_last_branches(self, function):
""" Apply the function on last branches before leaf.
def apply_on_last_level(self, function):
""" Apply the function on last level of the tree before leaf
:param function: (op, a, a) -> b
:returns: b if it is a 1 level Tree, Tree otherwise
@ -240,7 +240,7 @@ class Tree(object):
| > 4
> 2
>>> from .tree_tools import infix_str_concatenate
>>> tt = t.apply_on_last_branches(lambda *x: infix_str_concatenate(*x))
>>> tt = t.apply_on_last_level(lambda *x: infix_str_concatenate(*x))
>>> print(tt)
+
> 3 * 4
@ -250,13 +250,13 @@ class Tree(object):
left_is_leaf = 0
right_is_leaf = 0
try:
left_applied = self.left_value.apply_on_last_branches(function)
left_applied = self.left_value.apply_on_last_level(function)
except AttributeError:
left_applied = self.left_value
left_is_leaf = 1
try:
right_applied = self.right_value.apply_on_last_branches(function)
right_applied = self.right_value.apply_on_last_level(function)
except AttributeError:
right_applied = self.right_value
right_is_leaf = 1
@ -267,7 +267,7 @@ class Tree(object):
return Tree(self.node, left_applied, right_applied)
def apply(self, function):
""" Apply the function to the whole tree
""" Apply the function on every node of the tree
:param function: (op, a, a) -> b
:returns: b