new Tuple(List)
Simple tuple implementation. This constructor will create new instances
and store immutable values within them.
Parameters:
| Name | Type | Description |
|---|---|---|
List |
Array.<objects> | of values to store within the tuple. |
- Source:
Members
(inner) i
Contains the number of elements held within the tuple.
- Source:
Methods
equals(target) → {Boolean}
Compares each value in both tuples, one value at a time in order. Both
tuples have to be of the same length and need to contain the exact same
values for this to return true. This can be used to compare against any
array-like object.
Parameters:
| Name | Type | Description |
|---|---|---|
target |
Object | A tuple instance or any other array-like object you wish to compare to. |
- Source:
Returns:
True if the tuples length and values match, false if not.
- Type
- Boolean
forEach(callback)
Iterates over every value within the tuple and pass the said values to
the provided callback individually.
The callback is also passed the current index and tuple instance in that
order. This matches the normal `forEach` API found in most libraries and
modern JavaScript.
Parameters:
| Name | Type | Description |
|---|---|---|
callback |
function | Is passed every value in the tuple, one at a time. |
- Source:
toArray() → {Array.<object>}
Coerces the tuple into an array. This runs through
`Array.prototype.slice.call` because tuples are array-like objects.
- Source:
Returns:
All of the tuples values contained within an array.
- Type
- Array.<object>
toString() → {String}
Flattens the tuples values into a string.
- Source:
Returns:
A textual representation of the tuples contents.
- Type
- String
unpack(unpacker) → {object}
Passes the values as arguments, in the same order they were set, to the
provided unpacker function. It will return the value that the unpacker
returns.
Parameters:
| Name | Type | Description |
|---|---|---|
unpacker |
function | Is passed all of the tuples values in order, it's return value will be returned. |
- Source:
Returns:
The value that the unpacker function returns.
- Type
- object
valueOf() → {object}
Returns the product of adding all contained values together. If you only
have numbers within your tuple you will get back all of those numbers
added together. If you have strings too then you will get a string
containing all of the values.
This function is called automatically when using greater or less than
comparisons on tuples. So `tuple1 > tuple2` will add all of the
containing values together and then compare them.
- Source:
Returns:
The product of all values contained within the tuple.
- Type
- object