diff --git a/fx/src/main/kotlin/org/nwapw/abacus/fx/graphing/Graph.kt b/fx/src/main/kotlin/org/nwapw/abacus/fx/graphing/Graph.kt index e7bdde1..eacd458 100644 --- a/fx/src/main/kotlin/org/nwapw/abacus/fx/graphing/Graph.kt +++ b/fx/src/main/kotlin/org/nwapw/abacus/fx/graphing/Graph.kt @@ -1,7 +1,12 @@ 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.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.NumberInterface import org.nwapw.abacus.plugin.StandardPlugin @@ -30,4 +35,13 @@ class Graph(val abacus: Abacus, this.expression = expression this.pointExpression = pointExpression } + + fun evaluateWith(tree: TreeNode, values: List, + contextModifier: MutableEvaluationContext.(T) -> Unit) = runBlocking { + values.map { + val context = abacus.context.mutableSubInstance() + context.contextModifier(it) + async(CommonPool) { abacus.evaluateTreeWithContext(tree, context) } + }.map { it.await() } + } }