From 3bffa1c78f85f1995881c55ba2d29a9e88c6f485 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sun, 17 Sep 2017 22:30:11 -0700 Subject: [PATCH] Add a function to run inputs through an abacus expression. --- .../kotlin/org/nwapw/abacus/fx/graphing/Graph.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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() } + } }