diff --git a/core/src/main/java/org/nwapw/abacus/function/TreeValueFunction.java b/core/src/main/java/org/nwapw/abacus/function/TreeValueFunction.java index cd802c4..a34cecc 100644 --- a/core/src/main/java/org/nwapw/abacus/function/TreeValueFunction.java +++ b/core/src/main/java/org/nwapw/abacus/function/TreeValueFunction.java @@ -1,6 +1,7 @@ package org.nwapw.abacus.function; import org.nwapw.abacus.number.NumberInterface; +import org.nwapw.abacus.tree.Reducer; import org.nwapw.abacus.tree.TreeNode; /** @@ -9,4 +10,34 @@ import org.nwapw.abacus.tree.TreeNode; */ public abstract class TreeValueFunction extends Applicable { + @Override + protected NumberInterface applyInternal(TreeNode[] params) { + return null; + } + + @Override + public NumberInterface apply(TreeNode... params) { + return null; + } + + /** + * Applies the tree value functions to the given tree nodes, + * using the given reducer. + * @param reducer the reducer to use. + * @param params the parameters to apply to. + * @return the result of the application. + */ + public abstract NumberInterface applyWithReducerInternal(Reducer reducer, TreeNode[] params); + + /** + * Checks if the given parameters and reducer can be used + * with this function, and if so, calls the function on them. + * @param reducer the reducer to use. + * @param params the parameters to apply to. + * @return the result of the application, or null if the parameters are incompatible. + */ + public NumberInterface applyWithReducer(Reducer reducer, TreeNode... params) { + if(!matchesParams(params) || reducer == null) return null; + return applyWithReducerInternal(reducer, params); + } }