ciplogic.com
Live with grace. Write superb software.

It brings me great joy to announce the release of version 1.0.0 of core-lang, the collection classes I wrote for JavaScript.

Overview

With an API that is fully compatible with the JavaScript API, keeping the same signatures and behaviors for functions such as forEach, etc, but also inspired from groovy, having methods such as groupBy, chaining support, and full Promise support, allowing to deal with collections that contain promises, or are transformed to promises, using simple chainable calls.

 

The classes closely mimic the Java hierarchy, and inheritance rules, such as if you have an object that is an XArrayList, then calling on it:

1
2
3
4
5
var myArray = new XArrayList();
console.log(myArray instanceof XList); // true
console.log(myArray instanceof XCollection); // true
console.log(myArray instanceof XIterable); // true
console.log(myArray instanceof XSet); // false

will return true as expected.

UML

Here's an overview UML on what classes are available in the package:

Promise Support

Here's a small code sample on how promises support simplifies code, and improves readability:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
list([1,2,3,4])
    .map(Promise.resolve, Promise) // make them promises
    .mapPromise(function(it) {
        // mapPromise first resolves the items in the collection,
        // then it applies the mapping function
        // all the items are resolved at his stage, so we have the initial
        // array, being iterated over. We create new promises.
        return Promise.resolve(it * it);
    }).then(function(collection) {
        // not only the value before mapping gets resolved, but also
        // the result gets first Promise.resolved and only after
        // added back into the collection
        assert.equal([1,4,9,16], collection.asArray());
    });

Disqus Comments

comments powered by Disqus

Germanium

The one to rule them all. The browsers that is.

SharpKnight

SharpKnight is an Android chess game.

MagicGroup

MagicGroup is an eclipse plugin.