# Module: ink/collector

## ink/collector

An object and array collector

Source:
  - documents/collector.js, line 2

### Classes

ACollector
CollectorBase
OCollector

### Members

#### difference

  Creates an array of array elements not present in the other arrays using strict equality for comparisons, i.e. ===.

  Source:
    - documents/collector.js, line 278

#### head

  Gets the first n values of the array

  Source:
    - documents/collector.js, line 290

#### heap :object|array

  The collection that being managed

  ##### Type:

  - object | array
  Source:
    - documents/collector.js, line 26

#### tail

  This method gets all but the first values of array

  Source:
    - documents/collector.js, line 284

### Methods

#### <static> collect(obj) → {ACollector|OCollector}

  Collect an object

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `obj` | array | object | What to collect

  Source:
    - documents/collector.js, line 363

  ##### Returns:

  Type
    ACollector | OCollector

#### <inner> add(item)

  Adds to the top of the collection

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `item` | * | The item to add to the collection. Only one item at a time can be added

  Source:
    - documents/collector.js, line 296

#### <inner> add(key, item)

  Adds an item to the collection

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `key` | * | The key to use for the item being added.
  `item` | * | The item to add to the collection. The item is not iterated so that you could add bundled items to the collection

  Source:
    - documents/collector.js, line 56

#### <inner> append(item)

  Add to the bottom of the list

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `item` | * | The item to add to the collection. Only one item at a time can be added

  Source:
    - documents/collector.js, line 303

#### <inner> at(args)

  Creates an array of elements from the specified indexes, or keys, of the collection. Indexes may be specified as individual arguments or as arrays of indexes

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `args` | indexes | The indexes to use

  Source:
    - documents/collector.js, line 324

#### <inner> compact()

  Modifies the collection with all falsey values of array removed. The values false, null, 0, "", undefined and NaN are all falsey.

  Source:
    - documents/collector.js, line 316

#### <inner> countBy(query, iterator, thisobj) → {object}

  Creates an object composed of keys returned from running each element of the collection through the given callback. The corresponding value of each key is the number of times the key was returned by the callback.

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `query` | object | <optional> | A query to evaluate. If you pass in a query, only the items that match the query are iterated over.
  `iterator` | function |  |
  `thisobj` | object | <optional> | The value of `this`

  Source:
    - documents/collector.js, line 138

  ##### Returns:

  Type
    object

#### <inner> destroy()

  Destructor called when the object is destroyed.

  Source:
    - documents/collector.js, line 241

#### <inner> each(query, iterator, thisobj)

  Iterate over each item in the collection, or a subset that matches a query. This supports two signatures: `.each(query, function)` and `.each(function)`. If you pass in a query, only the items that match the query are iterated over.

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `query` | object | <optional> | A query to evaluate
  `iterator` | function |  | Function to execute against each item in the collection
  `thisobj` | object | <optional> | The value of `this`

  Source:
    - documents/collector.js, line 67

#### <inner> flatten(query, iterator,, thisobj) → {number}

  Flattens a nested array (the nesting can be to any depth). If isShallow is truthy, array will only be flattened a single level. If callback is passed, each element of array is passed through a callback before flattening.

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `query` | object | <optional> | A query to evaluate . If you pass in a query, only the items that match the query are iterated over.
  `iterator,` | function |  |
  `thisobj` | object | <optional> | The value of `this`

  Source:
    - documents/collector.js, line 338

  ##### Returns:

  Type
    number

#### <inner> groupBy(query, iterator, thisobj) → {object}

  Creates an object composed of keys returned from running each element of the collection through the callback. The corresponding value of each key is an array of elements passed to callback that returned the key. The callback is invoked with three arguments: (value, index|key, collection).

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `query` | object | <optional> | A query to evaluate . If you pass in a query, only the items that match the query are iterated over.
  `iterator` | function |  |
  `thisobj` | object | <optional> | The value of `this`

  Source:
    - documents/collector.js, line 157

  ##### Returns:

  Type
    object

#### <inner> index(key) → {*}

  Gets an items by its index

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `key` | number | The index to get

  Source:
    - documents/collector.js, line 352

  ##### Returns:

  Type
    *

#### <inner> key(key) → {*}

  Get a record by key

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `key` | * | The key of the record to get

  Source:
    - documents/collector.js, line 257

  ##### Returns:

  Type
    *

#### <inner> map(query, iterator, thisobj)

  Maps the contents to an array by iterating over it and transforming it. You supply the iterator. Supports two signatures: `.map(query, function)` and `.map(function)`. If you pass in a query, only the items that match the query are iterated over.

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `query` | object | <optional> | A query to evaluate
  `iterator` | function |  | Function to execute against each item in the collection
  `thisobj` | object | <optional> | The value of `this`

  Source:
    - documents/collector.js, line 99

#### <inner> max(query, iterator, thisobj) → {number}

  Retrieves the maximum value of an array. If callback is passed, it will be executed for each value in the array to generate the criterion by which the value is ranked.

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `query` | object | <optional> | A query to evaluate . If you pass in a query, only the items that match the query are iterated over.
  `iterator` | function |  |
  `thisobj` | object | <optional> | The value of `this`

  Source:
    - documents/collector.js, line 211

  ##### Returns:

  Type
    number

#### <inner> min(query, iterator, thisobj) → {number}

  Retrieves the minimum value of an array. If callback is passed, it will be executed for each value in the array to generate the criterion by which the value is ranked.

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `query` | object | <optional> | A query to evaluate . If you pass in a query, only the items that match the query are iterated over.
  `iterator` | function |  |
  `thisobj` | object | <optional> | The value of `this`

  Source:
    - documents/collector.js, line 229

  ##### Returns:

  Type
    number

#### <inner> pluck(query, property) → {*}

  Reduce the collection to a single value. Supports two signatures: `.pluck(query, function)` and `.pluck(function)`

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `query` | object | <optional> | The query to evaluate. If you pass in a query, only the items that match the query are iterated over.
  `property` | string |  | The property that will be 'plucked' from the contents of the collection

  Source:
    - documents/collector.js, line 174

  ##### Returns:

  Type
    *

#### <inner> push(item)

  Add an item to the top of the list. This is identical to `add`, but is provided for stack semantics

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `item` | * | The item to add to the collection. Only one item at a time can be added

  Source:
    - documents/collector.js, line 310

#### <inner> reduce(query, iterator, accumulator, thisobj) → {*}

  Reduces a collection to a value which is the accumulated result of running each element in the collection through the callback, where each successive callback execution consumes the return value of the previous execution. If accumulator is not passed, the first element of the collection will be used as the initial accumulator value. are iterated over.

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `query` | object | <optional> | A query to evaluate
  `iterator` | function |  | The function that will be executed in each item in the collection
  `accumulator` | * | <optional> | Initial value of the accumulator.
  `thisobj` | object | <optional> | The value of `this`

  Source:
    - documents/collector.js, line 119

  ##### Returns:

  Type
    *

#### <inner> sortBy(query, iterator, thisobj) → {array}

  Returns a sorted copy of the collection.

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `query` | object | <optional> | The query to evaluate. If you pass in a query, only the items that match the query are iterated over.
  `iterator` | function |  |
  `thisobj` | object | <optional> | The value of `this`

  Source:
    - documents/collector.js, line 193

  ##### Returns:

  Type
    array

#### <inner> toArray() → {array}

  Returns the collection as an array. If it is already an array, it just returns that.

  Source:
    - documents/collector.js, line 80

  ##### Returns:

  Type
    array

#### <inner> toJSON() → {object}

  Supports conversion to a JSON string or for passing over the wire

  Source:
    - documents/collector.js, line 88

  ##### Returns:

  - Type
      object
  - Type
      Object | array