mirror of
https://github.com/DanilaFe/abacus
synced 2024-07-01 23:06:11 -07:00
19 lines
596 B
Kotlin
19 lines
596 B
Kotlin
|
package org.nwapw.abacus.tree
|
||
|
|
||
|
/**
|
||
|
* A unary operator node that reduces its children.
|
||
|
*
|
||
|
* NumberUnaryNode operates by simply reducing its child,
|
||
|
* and using the result of that reduction to reduce itself.
|
||
|
* @param operation the operation this node performs.
|
||
|
* @param child the child this node should be applied to.
|
||
|
*/
|
||
|
class NumberUnaryNode(operation: String, child: TreeNode?)
|
||
|
: UnaryNode(operation, child) {
|
||
|
|
||
|
override fun <T : Any> reduce(reducer: Reducer<T>): T? {
|
||
|
val child = applyTo?.reduce(reducer) ?: return null
|
||
|
return reducer.reduceNode(this, child)
|
||
|
}
|
||
|
|
||
|
}
|