Search in sources :

Example 1 with IFn

use of clojure.lang.IFn in project enumerable by hraberg.

the class GroovyTest method interactingWithClojure.

@Test
public void interactingWithClojure() throws Exception {
    IFn star = (IFn) ClojureTest.getClojureEngine().eval("*");
    Closure<?> closure = toClosure(LambdaClojure.toFn2(star));
    groovy.put("f", closure);
    assertEquals(6L, groovy.eval("f(2, 3)"));
}
Also used : IFn(clojure.lang.IFn) 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)

Example 2 with IFn

use of clojure.lang.IFn 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 3 with IFn

use of clojure.lang.IFn in project enumerable by hraberg.

the class ClojureTest method convertIFnToFn.

@Test
public void convertIFnToFn() throws ScriptException {
    IFn star = eval("*");
    assertEquals(6L, toFn2(star).call(2, 3));
}
Also used : IFn(clojure.lang.IFn) 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 4 with IFn

use of clojure.lang.IFn in project enumerable by hraberg.

the class ClojureTest method interactingWithEnumerableJava.

@SuppressWarnings("unchecked")
@Test
public void interactingWithEnumerableJava() throws Exception {
    APersistentVector v = (APersistentVector) clj.eval("[1 2 3 4 5]");
    IFn star = (IFn) clj.eval("*");
    assertEquals(120L, Enumerable.inject(v, 1, toFn2(star)));
}
Also used : IFn(clojure.lang.IFn) APersistentVector(clojure.lang.APersistentVector) 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 5 with IFn

use of clojure.lang.IFn in project enumerable by hraberg.

the class ClojureTest method interactingWithJRuby.

@Test
public void interactingWithJRuby() throws Exception {
    ScriptEngine rb = JRubyTest.getJRubyEngine();
    RubyProc proc = (RubyProc) rb.eval(":*.to_proc");
    IFn times = toIFn(LambdaJRuby.toFn2(proc));
    assertEquals(6L, times.invoke(2, 3));
    defn("times-rb", times);
    assertEquals(120L, clj.eval("(reduce times-rb 1 [1, 2, 3, 4, 5])"));
}
Also used : IFn(clojure.lang.IFn) RubyProc(org.jruby.RubyProc) ScriptEngine(javax.script.ScriptEngine) 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)

Aggregations

IFn (clojure.lang.IFn)25 Test (org.junit.Test)16 GroovyTest (org.enumerable.lambda.support.groovy.GroovyTest)15 JavaScriptTest (org.enumerable.lambda.support.javascript.JavaScriptTest)15 JRubyTest (org.enumerable.lambda.support.jruby.JRubyTest)15 ScalaTest (org.enumerable.lambda.support.scala.ScalaTest)15 Keyword (clojure.lang.Keyword)8 PersistentArrayMap (clojure.lang.PersistentArrayMap)8 ArrayList (java.util.ArrayList)8 ClojureTest (org.enumerable.lambda.support.clojure.ClojureTest)4 ScriptEngine (javax.script.ScriptEngine)3 RubyProc (org.jruby.RubyProc)2 APersistentVector (clojure.lang.APersistentVector)1 IPersistentMap (clojure.lang.IPersistentMap)1 IPersistentVector (clojure.lang.IPersistentVector)1 ISeq (clojure.lang.ISeq)1 Closure (groovy.lang.Closure)1 FunctionFn2 (org.enumerable.lambda.support.javascript.LambdaJavaScript.FunctionFn2)1 LambdaJRuby (org.enumerable.lambda.support.jruby.LambdaJRuby)1 ScalaInterpreter (org.enumerable.lambda.support.scala.ScalaTest.ScalaInterpreter)1