Search in sources :

Example 1 with ClosureFn2

use of org.enumerable.lambda.support.groovy.LambdaGroovy.ClosureFn2 in project enumerable by hraberg.

the class GroovyTest method interactingWithJavaScript.

@Test
public void interactingWithJavaScript() throws Exception {
    ScriptEngine js = JavaScriptTest.getJavaScriptEngine();
    Function f = (Function) js.eval("var f = function(n, m) { return n * m; }; f;");
    ClosureFn2 closure = toClosure(LambdaJavaScript.toFn2(f));
    assertEquals(6.0, closure.call(new Object[] { 2, 3 }));
    groovy.put("closure", closure);
    assertEquals(120.0, groovy.eval("[1, 2, 3, 4, 5].inject(1, closure)"));
}
Also used : Function(sun.org.mozilla.javascript.internal.Function) ClosureFn2(org.enumerable.lambda.support.groovy.LambdaGroovy.ClosureFn2) ScriptEngine(javax.script.ScriptEngine) ScalaTest(org.enumerable.lambda.support.scala.ScalaTest) JRubyTest(org.enumerable.lambda.support.jruby.JRubyTest) Test(org.junit.Test) ClojureTest(org.enumerable.lambda.support.clojure.ClojureTest) JavaScriptTest(org.enumerable.lambda.support.javascript.JavaScriptTest)

Aggregations

ScriptEngine (javax.script.ScriptEngine)1 ClojureTest (org.enumerable.lambda.support.clojure.ClojureTest)1 ClosureFn2 (org.enumerable.lambda.support.groovy.LambdaGroovy.ClosureFn2)1 JavaScriptTest (org.enumerable.lambda.support.javascript.JavaScriptTest)1 JRubyTest (org.enumerable.lambda.support.jruby.JRubyTest)1 ScalaTest (org.enumerable.lambda.support.scala.ScalaTest)1 Test (org.junit.Test)1 Function (sun.org.mozilla.javascript.internal.Function)1