ProductPromotion
Logo

Java.Script

made by https://0x3d.site

GitHub - swannodette/mori: ClojureScript's persistent data structures and supporting API from the comfort of vanilla JavaScript
ClojureScript's persistent data structures and supporting API from the comfort of vanilla JavaScript - swannodette/mori
Visit Site

GitHub - swannodette/mori: ClojureScript's persistent data structures and supporting API from the comfort of vanilla JavaScript

GitHub - swannodette/mori: ClojureScript's persistent data structures and supporting API from the comfort of vanilla JavaScript

mori

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

Breaking changes in 0.3.0

The API now uses idiomatic JavaScript naming conventions.

Improvements to 0.3.0

Faster

Mori is considerably faster across the board thanks to recent enhancements to the ClojureScript compiler. For users who would like to benchmark their immutable data structure implementations against Mori, Mori now exposes direct arity invokes which eliminates previous calling overheads from arity dispatching. See Benchmarking for more information.

Mori hash maps now default to ClojureScript ArrayMaps that are automatically promoted to PersistentHashMaps as needed. ArrayMaps deliver considerably better performance at small sizes and when simple keys are at play. For example a Mori hash map with less than or equal to eight keys can now be built nearly an order of magnitude faster than Immutable.js 3.6.2 Maps.

More ES6

All Mori collections support ES6 iteration via foo[Symbol.iterator] or foo["@@iterator"].

Differences from Immutable.js

  • A functional API, data structures do not have public methods
  • Faster, ClojureScript data structures have been subjected to more real world usage and continuous benchmarking for nearly 4 years
  • Larger, gzipped the base Mori module is about 6K larger than Immutable.js

Getting it

You can install the latest release via npm:

npm install mori

The installed package contains a single optimized JavaScript file mori.js.

Load mori in your Node.js programs as you would any other module:

var mori = require("mori");

In a browser, you can load mori with a script tag, as you would any other JavaScript library:

<script src="mori.js" type="text/javascript"></script>

You can also load it as an AMD module, e.g. with RequireJS.

Usage

You can use it from your projects like so:

var inc = function(n) {
  return n+1;
};

mori.intoArray(mori.map(inc, 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;
_.intoArray(_.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.intoArray r

Documentation

You can find extensive documentation and examples here.

More Examples

Efficient Freeze/Thaw

For vectors and maps we provide an efficient thaw and freeze operations:

var m = mori;

// ~220ms with V8 version 3.29.80 MBP 2.26ghz
for(var j = 0; j < 10; j++) {
  var s = new Date();
  var arr = [];
  for(var i = 0; i < 10000000; i++) {
    arr.push(i);
  }
  print("Array push " + arr.length + " items " + ((new Date())-s));
  gc();
}

// ~70ms
for(var j = 0; j < 10; j++) {
  s = new Date();
  var mv = m._thaw(m.vector());
  for(var i = 0; i < 10000000; i++) {
    mv = m._conj.f2(mv, i);
  }
  var v = m._freeze(mv);
  print("Mutable vector conj " + m.count(v) + " items " + ((new Date())-s));
  gc();
}

ES6 Map/Set inspired interfaces

All Mori maps and sets support all the non-mutating methods of the proposed ES6 Map and Set interfaces. The main difference with the spec is that key lookup is based on value not reference. keys, values, and entries methods return the proposed mutable iterators:

var m = mori;
var h = m.hashMap("foo", 1, "bar", 2);

h.has("foo"); // => true
h.get("foo"); // => 1

var iter = h.keys();
iter.next(); // => {done: false, value: "foo"}

This feature is subject to changes in the ES6 proposal.

Transducers

Mori includes Transducers. Zero allocation collection operations FTW:

var m = mori;
var a = [];

for(var i = 0; i < 1000000; i++) {
  a.push(i);
}

// make it immutable
var v = m.into(m.vector(), a);

function time(f) {
  var s = new Date();
  f();
  console.log(((new Date())-s)+"ms");
}

// ~190ms V8 version 3.29.80 MBP 2.26ghz
time(function() {
  var xf = m.comp(m.map(m.inc), m.map(m.inc), m.map(m.inc));
  return m.transduce(xf, m.completing(m.sum), 0, v);
}, 10);

// ~440ms
time(function() {
  return a.map(m.inc).map(m.inc).map(m.inc).reduce(function(a,b){return a+b;}, 0);
}, 10);

Build

Prerequisites

You will first need to install the Java SDK, if it's not already installed on your system.

On Windows, you will need to manually install Leiningen. On UNIX-like systems, Leiningen will be installed within the project automatically if the lein executable is not found on your path or if your lein version predates 2.0.0.

Clone the repo

git clone https://github.com/swannodette/mori.git
cd mori

On a UNIX-like system build with

./scripts/build.sh

Alternatively using npm

npm run-script build

On Windows

./scripts/build.ps1

The build process will generate an optimized JavaScript file mori.js, which is suitable for use with Node.js, or in a Web browser or other JavaScript environments. You can also load it as an AMD module.

Copyright (C) 2012-2015 David Nolen and contributors

Distributed under the Eclipse Public License, the same as Clojure.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory