ClojureScript's persistent data structures and supporting API from the comfort of vanilla JavaScript
Clojure
Switch branches/tags
Nothing to show
Pull request Compare This branch is 281 commits behind swannodette:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
.gitignore
README.md
project.clj

README.md

Mori

A simple bridge to ClojureScript's persistent data structures and supporting APIs for vanilla JavaScript. Pull requests welcome.

Usage

You can download the latest prebuilt version of Mori from the downloads tab.

Caveats

Pre-pre-pre alpha. ClojureScript is constantly being improved, especially in terms of performance. That said, it's probably still already useful.

Build

Make a folder in the repo folder called checkouts, clone the ClojureScript repo into it.

Install Leiningen.

Grab dependencies:

lein deps

Build with:

lein cljsbuild once release

This 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)); // => 10

Lazy 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)

Reducers

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.