aboutsummaryrefslogtreecommitdiff
path: root/tools/addon-sdk-1.4/packages/api-utils/docs/list.md
blob: 8e1a5221bc2ddfd6aaa3cb0e577c5a7ad57a026c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<!-- contributed by Irakli Gozalishvili [gozala@mozilla.com]  -->

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

<api name="Iterable">
@class
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.

<api name="Iterable">
@constructor
Constructs an `Iterable` object.
</api>

<api name="_keyValueMap">
@property {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._
</api>

</api>

<api name="List">
@class
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.

**Examples:**

    var MyList = List.compose({
      add: function add(item1, item2, /*item3...*/) {
        Array.slice(arguments).forEach(this._add.bind(this));
      },
      remove: function remove(item1, item2, /*item3...*/) {
        Array.slice(arguments).forEach(this._remove.bind(this));
      }
    });
    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

<api name="List">
@constructor
Constructor can takes any number of elements and creates an instance of
`List` populated with the specified elements.
@param [element1] {Object|String|Number}
@param [element2] {Object|String|Number}
@param [...] {Object|String|Number}
</api>

<api name="length">
@property {Number}
Number of elements in this list.
</api>

<api name="_has">
@method
@param element {Object|Number|String}
Returns `true` if this list contains the specified `element`.
</api>
<api name="_add">
@method
@param 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._
</api>
<api name="_remove">
@method
@param element {Object|Number|String}
Removes specified `element` from this list, if it contains it.

_Ignores the call if `element` is not contained._
</api>
<api name="_clear">
@method
Removes all of the elements from this list.
</api>
</api>