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)"));
}
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])"));
}
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));
}
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)));
}
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])"));
}
Aggregations