diff --git a/src/main/java/org/nwapw/abacus/tree/Reducer.java b/src/main/java/org/nwapw/abacus/tree/Reducer.java deleted file mode 100644 index b7bbdbd..0000000 --- a/src/main/java/org/nwapw/abacus/tree/Reducer.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.nwapw.abacus.tree; - -/** - * Interface used to reduce a tree into a single value. - * - * @param the value to reduce into. - */ -public interface Reducer { - - /** - * Reduces the given tree into a single value of type T. - * - * @param node the node being passed in to be reduced. - * @param children the already-reduced children of this node. - * @return the resulting value from the reduce. - */ - public T reduceNode(TreeNode node, Object... children); - -} diff --git a/src/main/kotlin/org/nwapw/abacus/tree/FunctionNode.kt b/src/main/kotlin/org/nwapw/abacus/tree/FunctionNode.kt index 198eee2..b101792 100644 --- a/src/main/kotlin/org/nwapw/abacus/tree/FunctionNode.kt +++ b/src/main/kotlin/org/nwapw/abacus/tree/FunctionNode.kt @@ -16,7 +16,7 @@ data class FunctionNode(val function: String) : TreeNode() { val children: MutableList = mutableListOf() override fun reduce(reducer: Reducer): T? { - val children = Array(children.size, { children[it].reduce(reducer) ?: return null; }) + val children = Array(children.size, { children[it].reduce(reducer) ?: return null; }) return reducer.reduceNode(this, *children) } diff --git a/src/main/kotlin/org/nwapw/abacus/tree/Reducer.kt b/src/main/kotlin/org/nwapw/abacus/tree/Reducer.kt new file mode 100644 index 0000000..4277185 --- /dev/null +++ b/src/main/kotlin/org/nwapw/abacus/tree/Reducer.kt @@ -0,0 +1,19 @@ +package org.nwapw.abacus.tree + +/** + * Reducer interface that takes a tree and returns a single value. + * + * The reducer walks the tree, visiting the children first, converting them into + * a value, and then attempts to reduce the parent. Eventually, the single final value is returned. + */ +interface Reducer { + + /** + * Reduces the given tree node, given its already reduced children. + * + * @param treeNode the tree node to reduce. + * @param children the list of children, of type T. + */ + fun reduceNode(treeNode: TreeNode, vararg children: Any) : T? + +} \ No newline at end of file