Refact(Tree): Rename type_function to fallback in apply_on_last_level

This commit is contained in:
Bertrand Benjamin 2018-11-14 16:06:37 +01:00
parent eae88d6c4c
commit ecf7e7678f
1 changed files with 6 additions and 6 deletions

View File

@ -296,11 +296,11 @@ class Tree(object):
def apply_on_last_level(self,
function,
type_function = lambda n,l,r: Tree(n,l,r)):
fallback = lambda n,l,r: Tree(n,l,r)):
""" Apply the function on last level of the tree before leaf
:param function: (op, a, a) -> b function to apply on last level
:param type_function: (op, a, a) -> b typing function to apply on subtree which raise a TypeError. The return value will be concidered as an leaf
:param fallback: (op, a, a) -> b fallback function to apply on subtree which raise a NotImplementedError. The return value will be concidered as an leaf
:returns: b if it is a 1 level Tree, Tree otherwise
@ -333,12 +333,12 @@ class Tree(object):
right_is_leaf = 0
try:
left_applied = self.left_value.\
apply_on_last_level(function, type_function)
apply_on_last_level(function, fallback)
except NotImplementedError:
# TODO: overload __getitem__ to ease unpacking |dim. sept. 23 19:17:50 CEST 2018
left_is_leaf = 1
left_tree = self.left_value
left_applied = type_function(left_tree.node,
left_applied = fallback(left_tree.node,
left_tree.left_value,
left_tree.right_value)
except AttributeError:
@ -347,11 +347,11 @@ class Tree(object):
try:
right_applied = self.right_value.\
apply_on_last_level(function, type_function)
apply_on_last_level(function, fallback)
except NotImplementedError:
right_is_leaf = 1
right_tree = self.right_value
right_applied = type_function(right_tree.node,
right_applied = fallback(right_tree.node,
right_tree.left_value,
right_tree.right_value)
except AttributeError: