UNPKG

1.42 kBJavaScriptView Raw
1'use strict';
2
3function factory(type, config, load, typed) {
4 /**
5 * Wrap any value in a chain, allowing to perform chained operations on
6 * the value.
7 *
8 * All methods available in the math.js library can be called upon the chain,
9 * and then will be evaluated with the value itself as first argument.
10 * The chain can be closed by executing `chain.done()`, which returns
11 * the final value.
12 *
13 * The chain has a number of special functions:
14 *
15 * - `done()` Finalize the chain and return the chain's value.
16 * - `valueOf()` The same as `done()`
17 * - `toString()` Executes `math.format()` onto the chain's value, returning
18 * a string representation of the value.
19 *
20 * Syntax:
21 *
22 * math.chain(value)
23 *
24 * Examples:
25 *
26 * math.chain(3)
27 * .add(4)
28 * .subtract(2)
29 * .done() // 5
30 *
31 * math.chain( [[1, 2], [3, 4]] )
32 * .subset(math.index(0, 0), 8)
33 * .multiply(3)
34 * .done() // [[24, 6], [9, 12]]
35 *
36 * @param {*} [value] A value of any type on which to start a chained operation.
37 * @return {math.type.Chain} The created chain
38 */
39 return typed('chain', {
40 '': function _() {
41 return new type.Chain();
42 },
43
44 'any': function any(value) {
45 return new type.Chain(value);
46 }
47 });
48}
49
50exports.name = 'chain';
51exports.factory = factory;
\No newline at end of file