Search in sources :

Example 1 with IPersistentVector

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

the class ClojureTest method interactingWithClojure.

@Test
public void interactingWithClojure() throws Exception {
    eval("(def v [1 2 3 4 5])");
    IPersistentVector v = eval("v");
    IFn times = defn("times", fn(n, m, n * m));
    Integer factorial = 120;
    assertEquals(factorial, (reduce(times, 1, v)));
    assertEquals(factorial, eval(reduce, times, 1, v));
    assertEquals(factorial, eval("(reduce times 1 v)"));
    IFn isOdd = eval("odd?");
    ISeq odd = list(1L, 3L, 5L);
    assertEquals(odd, (filter(isOdd, v)));
    assertEquals(odd, eval(filter, isOdd, v));
    assertEquals(odd, eval("(filter odd? v)"));
    IFn isEven = defn("is-even?", toIFn(Lambda.λ(n, n % 2 == 0)));
    ISeq even = list(2L, 4L);
    assertEquals(even, (filter(isEven, v)));
    assertEquals(even, eval(filter, isEven, v));
    assertEquals(even, eval("(filter is-even? v)"));
}
Also used : IFn(clojure.lang.IFn) ISeq(clojure.lang.ISeq) IPersistentVector(clojure.lang.IPersistentVector) 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)1 IPersistentVector (clojure.lang.IPersistentVector)1 ISeq (clojure.lang.ISeq)1 GroovyTest (org.enumerable.lambda.support.groovy.GroovyTest)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