The "list" module provides base building blocks for composing lists.

API Reference



Base trait that can be used to compose traits with non-standard enumeration behaviors.

This trait is supposed to be used as part of a composition, since it only provides custom enumeration behavior to a composed object. It defines one required _keyValueMap property, that is used as a hash of "key-values" to iterate on during enumeration.


Constructs an Iterable object.

_keyValueMap : Object

Hash map of key-values to iterate over. Required property: that is, the property must be supplied by objects that compose this trait. Note: That this property can be a getter if you need dynamic behavior.


An ordered collection (also known as a sequence) disallowing duplicate elements. List is composed out of Iterable, therefore it provides custom enumeration behavior that is similar to array (enumerates only on the elements of the list).

List is a base trait and is meant to be part of a composition, since all of its API is private except for the length property.


var MyList = List.compose({
  add: function add(item1, item2, /*item3...*/) {
  remove: function remove(item1, item2, /*item3...*/) {
MyList('foo', 'bar', 'baz').length == 3;        // true
new MyList('new', 'keyword').length == 2;       // true
MyList.apply(null, [1, 2, 3]).length == 3;      // true
let list = MyList();
list.length == 0;                               // true
list.add(1, 2, 3) == 3;                         // true
List(element1, element2, ...)

Constructor can takes any number of elements and creates an instance of List populated with the specified elements.

[ element1 : Object|String|Number ]
[ element2 : Object|String|Number ]
[ ... : Object|String|Number ]
element : Object|Number|String

Returns true if this list contains the specified element.

element : Object|Number|String

Appends the specified element to the end of this list, if it doesn't contain it.

Ignores the call if element is already contained.

element : Object|Number|String

Removes specified element from this list, if it contains it.

Ignores the call if element is not contained.


Removes all of the elements from this list.

length : Number

Number of elements in this list.