Search in sources :

Example 1 with ScalaInterpreter

use of org.enumerable.lambda.support.scala.ScalaTest.ScalaInterpreter in project enumerable by hraberg.

the class ClojureTest method interactingWithScala.

@SuppressWarnings("unchecked")
@Test
public void interactingWithScala() throws Exception {
    ScalaInterpreter scala = ScalaTest.getScalaInterpreter();
    Function2<Long, Long, Long> f = (Function2<Long, Long, Long>) scala.eval("(n: Long, m: Long) => n * m");
    IFn times = toIFn(LambdaScala.toFn2(f));
    assertEquals(6L, times.invoke(2L, 3L));
    defn("times-scala", times);
    assertEquals(120L, clj.eval("(reduce times-scala 1 [1, 2, 3, 4, 5])"));
}
Also used : IFn(clojure.lang.IFn) ScalaInterpreter(org.enumerable.lambda.support.scala.ScalaTest.ScalaInterpreter) Function2(scala.Function2) GroovyTest(org.enumerable.lambda.support.groovy.GroovyTest) ScalaTest(org.enumerable.lambda.support.scala.ScalaTest) JRubyTest(org.enumerable.lambda.support.jruby.JRubyTest) Test(org.junit.Test) JavaScriptTest(org.enumerable.lambda.support.javascript.JavaScriptTest)

Example 2 with ScalaInterpreter

use of org.enumerable.lambda.support.scala.ScalaTest.ScalaInterpreter in project enumerable by hraberg.

the class JavaScriptTest method interactingWithScala.

@SuppressWarnings("unchecked")
@Test
public void interactingWithScala() throws Exception {
    ScalaInterpreter scala = ScalaTest.getScalaInterpreter();
    Function2<Integer, Integer, Integer> f = (Function2<Integer, Integer, Integer>) scala.eval("(n: Double, m: Double) => n * m");
    js.put("f", toFunction(LambdaScala.toFn2(f)));
    assertEquals(6.0, js.eval("f(2, 3)"));
}
Also used : ScalaInterpreter(org.enumerable.lambda.support.scala.ScalaTest.ScalaInterpreter) Function2(scala.Function2) GroovyTest(org.enumerable.lambda.support.groovy.GroovyTest) 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)

Example 3 with ScalaInterpreter

use of org.enumerable.lambda.support.scala.ScalaTest.ScalaInterpreter in project enumerable by hraberg.

the class JRubyTest method interactingWithScala.

@SuppressWarnings("unchecked")
@Test
public void interactingWithScala() throws Exception {
    Ruby ruby = Ruby.getGlobalRuntime();
    ScalaInterpreter scala = ScalaTest.getScalaInterpreter();
    Function2<Integer, Integer, Integer> f = (Function2<Integer, Integer, Integer>) scala.eval("(n: Long, m: Long) => n * m");
    RubyProc proc = toProc(LambdaScala.toFn2(f));
    assertEquals(ruby.newFixnum(6), proc.call(ruby.getThreadService().getCurrentContext(), new IRubyObject[] { ruby.newFixnum(2), ruby.newFixnum(3) }));
    rb.put("block", proc);
    assertEquals(120L, rb.eval("[1, 2, 3, 4, 5].inject &block"));
}
Also used : RubyProc(org.jruby.RubyProc) ScalaInterpreter(org.enumerable.lambda.support.scala.ScalaTest.ScalaInterpreter) Function2(scala.Function2) IRubyObject(org.jruby.runtime.builtin.IRubyObject) Ruby(org.jruby.Ruby) LambdaJRuby(org.enumerable.lambda.support.jruby.LambdaJRuby) GroovyTest(org.enumerable.lambda.support.groovy.GroovyTest) ScalaTest(org.enumerable.lambda.support.scala.ScalaTest) Test(org.junit.Test) ClojureTest(org.enumerable.lambda.support.clojure.ClojureTest) JavaScriptTest(org.enumerable.lambda.support.javascript.JavaScriptTest)

Example 4 with ScalaInterpreter

use of org.enumerable.lambda.support.scala.ScalaTest.ScalaInterpreter in project enumerable by hraberg.

the class GroovyTest method interactingWithScala.

@SuppressWarnings("unchecked")
@Test
public void interactingWithScala() throws Exception {
    ScalaInterpreter scala = ScalaTest.getScalaInterpreter();
    Function2<Integer, Integer, Integer> f = (Function2<Integer, Integer, Integer>) scala.eval("(n: Int, m: Int) => n * m");
    Closure<?> closure = toClosure(LambdaScala.toFn2(f));
    groovy.put("closure", closure);
    assertEquals(120, groovy.eval("[1, 2, 3, 4, 5].inject(1, closure)"));
}
Also used : ScalaInterpreter(org.enumerable.lambda.support.scala.ScalaTest.ScalaInterpreter) Function2(scala.Function2) 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

ScalaTest (org.enumerable.lambda.support.scala.ScalaTest)4 ScalaInterpreter (org.enumerable.lambda.support.scala.ScalaTest.ScalaInterpreter)4 Test (org.junit.Test)4 Function2 (scala.Function2)4 ClojureTest (org.enumerable.lambda.support.clojure.ClojureTest)3 GroovyTest (org.enumerable.lambda.support.groovy.GroovyTest)3 JavaScriptTest (org.enumerable.lambda.support.javascript.JavaScriptTest)3 JRubyTest (org.enumerable.lambda.support.jruby.JRubyTest)3 IFn (clojure.lang.IFn)1 LambdaJRuby (org.enumerable.lambda.support.jruby.LambdaJRuby)1 Ruby (org.jruby.Ruby)1 RubyProc (org.jruby.RubyProc)1 IRubyObject (org.jruby.runtime.builtin.IRubyObject)1