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