use of clojure.lang.IFn in project enumerable by hraberg.
the class ClojureTest method interactingWithJavaScript.
@Test
public void interactingWithJavaScript() throws Exception {
ScriptEngine js = JavaScriptTest.getJavaScriptEngine();
Function f = (Function) js.eval("var f = function(n, m) { return n * m; }; f;");
IFn times = toIFn(LambdaJavaScript.toFn2(f));
assertEquals(6.0, times.invoke(2, 3));
defn("times-js", times);
assertEquals(120.0, clj.eval("(reduce times-js 1 [1, 2, 3, 4, 5])"));
}
use of clojure.lang.IFn in project enumerable by hraberg.
the class ClojureTest method convertedFnToIFnThrowsArityWhenCalledWithTooManyArguments.
@Test(expected = IllegalArgumentException.class)
public void convertedFnToIFnThrowsArityWhenCalledWithTooManyArguments() throws Exception {
IFn fn = toIFn(Lambda.λ(s, s.toUpperCase()));
fn.invoke("hello", "world");
}
use of clojure.lang.IFn in project enumerable by hraberg.
the class JRubyTest method interactingWithClojure.
@Test
public void interactingWithClojure() throws Exception {
Ruby ruby = Ruby.getGlobalRuntime();
IFn star = (IFn) ClojureTest.getClojureEngine().eval("*");
RubyProc proc = toProc(LambdaClojure.toFn2(star));
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"));
}
use of clojure.lang.IFn in project storm by nathanmarz.
the class ClojureBolt method prepare.
@Override
public void prepare(final Map stormConf, final TopologyContext context, final OutputCollector collector) {
IFn hof = Utils.loadClojureFn(_fnSpec.get(0), _fnSpec.get(1));
try {
IFn preparer = (IFn) hof.applyTo(RT.seq(_params));
final Map<Keyword, Object> collectorMap = new PersistentArrayMap(new Object[] { Keyword.intern(Symbol.create("output-collector")), collector, Keyword.intern(Symbol.create("context")), context });
List<Object> args = new ArrayList<Object>() {
{
add(stormConf);
add(context);
add(collectorMap);
}
};
_bolt = (IBolt) preparer.applyTo(RT.seq(args));
//this is kind of unnecessary for clojure
try {
_bolt.prepare(stormConf, context, collector);
} catch (AbstractMethodError ame) {
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of clojure.lang.IFn in project jstorm by alibaba.
the class ClojureBolt method prepare.
@Override
public void prepare(final Map stormConf, final TopologyContext context, final OutputCollector collector) {
IFn hof = Utils.loadClojureFn(_fnSpec.get(0), _fnSpec.get(1));
try {
IFn preparer = (IFn) hof.applyTo(RT.seq(_params));
final Map<Keyword, Object> collectorMap = new PersistentArrayMap(new Object[] { Keyword.intern(Symbol.create("output-collector")), collector, Keyword.intern(Symbol.create("context")), context });
List<Object> args = new ArrayList<Object>() {
{
add(stormConf);
add(context);
add(collectorMap);
}
};
_bolt = (IBolt) preparer.applyTo(RT.seq(args));
// this is kind of unnecessary for clojure
try {
_bolt.prepare(stormConf, context, collector);
} catch (AbstractMethodError ame) {
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations