A simple bridge to ClojureScript's persistent data structures and supporting APIs for vanilla JavaScript. Pull requests welcome.
You can download the latest prebuilt version of Mori from the downloads tab.
Pre-pre-pre alpha. ClojureScript is constantly being improved, especially in terms of performance. That said, it's probably still already useful.
Make a folder in the repo folder called checkouts, clone the ClojureScript repo into it.
Install Leiningen.
Grab dependencies:
lein depsBuild with:
lein cljsbuild once releaseThis will produce a file mori.js. You can include this like any other JavaScript library.
You can use it from your projects like so:
mori.into_array(mori.map(function(x) { return x+1;}, mori.vector(1,2,3,4,5)));
// => [2,3,4,5,6]Efficient non-destructive updates!
var v1 = mori.vector(1,2,3);
var v2 = mori.conj(v1, 4);
v1.toString(); // => '[1 2 3]'
v2.toString(); // => '[1 2 3 4]'var sum = function(a, b) {
return a + b;
};
mori.reduce(sum, mori.vector(1, 2, 3, 4)); // => 10Lazy sequences!
var _ = mori;
_.into_array(_.interpose("foo", _.vector(1, 2, 3, 4)));
// => [1, "foo", 2, "foo", 3, "foo", 4]Or if it's more your speed, use it from CoffeeScript!
inc = (x) -> x+1
r = mori.map(inc, mori.vector(1,2,3,4,5))
mori.into_array(r)Mori includes the new Clojure reducers framework. Zero allocation collection operations FTW:
var m = mori;
var a = [];
for(var i = 0; i < 100000; i++) {
a.push(i);
}
// make it immutable
var v = m.into(m.vector(), a);
m.reduce(m.sum, 0, m.rmap(m.inc, m.rfilter(m.is_even, v)));Copyright (C) 2012 David Nolen
Distributed under the Eclipse Public License, the same as Clojure.