From e64613f5bee56c375b0138545a8be437a41c0850 Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Sun, 21 Jan 2018 11:52:22 +0300 Subject: [PATCH] map_leaf method for tree --- mapytex/calculus/core/tree.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/mapytex/calculus/core/tree.py b/mapytex/calculus/core/tree.py index 9f16103..20be43b 100644 --- a/mapytex/calculus/core/tree.py +++ b/mapytex/calculus/core/tree.py @@ -194,15 +194,27 @@ class Tree(object): ... ("*", (3, 4)), ... 2)) >>> t = Tree.from_nested_parenthesis(nested_par) + >>> print(t) + + + > * + | > 3 + | > 4 + > 2 + >>> print(t.map_leaf(lambda x:2*x)) + + + > * + | > 6 + | > 8 + > 4 """ try: - left_applied = self.left_value.apply(function) + left_applied = self.left_value.map_leaf(function) except AttributeError: left_applied = function(self.left_value) try: - right_applied = self.right_value.apply(function) + right_applied = self.right_value.map_leaf(function) except AttributeError: right_applied = function(self.right_value)