1
0
mirror of https://github.com/DanilaFe/abacus synced 2024-11-16 07:33:09 -08:00

Add a function to run inputs through an abacus expression.

This commit is contained in:
Danila Fedorin 2017-09-17 22:30:11 -07:00
parent b0cddf75f0
commit 3bffa1c78f

View File

@ -1,7 +1,12 @@
package org.nwapw.abacus.fx.graphing package org.nwapw.abacus.fx.graphing
import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.experimental.async
import kotlinx.coroutines.experimental.runBlocking
import org.nwapw.abacus.Abacus import org.nwapw.abacus.Abacus
import org.nwapw.abacus.config.Configuration import org.nwapw.abacus.config.Configuration
import org.nwapw.abacus.context.EvaluationContext
import org.nwapw.abacus.context.MutableEvaluationContext
import org.nwapw.abacus.number.NaiveNumber import org.nwapw.abacus.number.NaiveNumber
import org.nwapw.abacus.number.NumberInterface import org.nwapw.abacus.number.NumberInterface
import org.nwapw.abacus.plugin.StandardPlugin import org.nwapw.abacus.plugin.StandardPlugin
@ -30,4 +35,13 @@ class Graph(val abacus: Abacus,
this.expression = expression this.expression = expression
this.pointExpression = pointExpression this.pointExpression = pointExpression
} }
fun <T> evaluateWith(tree: TreeNode, values: List<T>,
contextModifier: MutableEvaluationContext.(T) -> Unit) = runBlocking {
values.map {
val context = abacus.context.mutableSubInstance()
context.contextModifier(it)
async(CommonPool) { abacus.evaluateTreeWithContext(tree, context) }
}.map { it.await() }
}
} }